# editor: Fix stale session path for renamed files \(\#52539\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/1cd3249ca9dfbeb7f8ee9f20256b4f01f55c9293)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 1cd3249ca9dfbeb7f8ee9f20256b4f01f55c9293

Requested commit: 1cd3249ca9dfbeb7f8ee9f20256b4f01f55c9293

Commit: 1cd3249ca9dfbeb7f8ee9f20256b4f01f55c9293

Tree: b1ebd97f3157b805a54606afe8bdb67bc5ddee90

Author: saberoueslati

Committer: GitHub

## Message

```
editor: Fix stale session path for renamed files (#52539)

## Context

When a file is renamed via the project panel while open in an editor,
Zed would restore the old (no longer existing) path on reload .

On rename, `language::Buffer` emits `BufferEvent::FileHandleChanged`,
which propagates to `multi_buffer::Event::FileHandleChanged` →
`EditorEvent::TitleChanged`. However, `should_serialize()` only matched
`Saved | DirtyChanged | BufferEdited`, so no re-serialization was
triggered and the `editors` DB table retained the stale `abs_path`.

The fix adds a dedicated `EditorEvent::FileHandleChanged` variant, emits
it alongside `TitleChanged` when the buffer's file handle changes, and
adds it to `should_serialize()`. Since `Editor::serialize()` already
reads the current path from the buffer at call time, this naturally
writes the new path to the DB.

Closes #51629

## How to Review

Three files edited:
- `editor.rs`: splits `FileHandleChanged` into its own arm and emits the
new event variant
- `items.rs`: adds `FileHandleChanged` to `should_serialize`
- `items.rs` (test): `test_file_handle_changed_on_rename` does a full
rename via `Project::rename_entry` and asserts the event fires and the
buffer path updates

## Self-Review Checklist

- [x] I've reviewed my own diff for quality, security, and reliability
- [ ] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Release Notes:

- Fixed renamed files being reopened with their old path after a restart

**Important remark :**
This pull request is a follow-up on the review of @SomeoneToIgnore on
this pull request, https://github.com/zed-industries/zed/pull/51717,
which was inadvertently closed because I mistakenly deleted my previous
fork of the zed repo, sorry for any inconvenience caused by this

Manual test video below :

[Screencast from 2026-03-16
23-28-46.webm](https://github.com/user-attachments/assets/ff2e3259-ae26-4655-83b8-f693e84306d2)
```

## Parents

- [e613b2c9d36f48248018d3684ddd034f2eade31e](https://git.cafe/gitcafe/zed/commit/e613b2c9d36f48248018d3684ddd034f2eade31e?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/1cd3249ca9dfbeb7f8ee9f20256b4f01f55c9293?format=markdown)
