Skip to content

editor: Fix stale session path for renamed files#52539

Merged
ChristopherBiscardi merged 5 commits intozed-industries:mainfrom
saberoueslati:editor-fix-renamed-file-stale-session-path
Apr 15, 2026
Merged

editor: Fix stale session path for renamed files#52539
ChristopherBiscardi merged 5 commits intozed-industries:mainfrom
saberoueslati:editor-fix-renamed-file-stale-session-path

Conversation

@saberoueslati
Copy link
Copy Markdown
Contributor

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::FileHandleChangedEditorEvent::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

  • I've reviewed my own diff for quality, security, and reliability
  • Unsafe blocks (if any) have justifying comments
  • The content is consistent with the UI/UX checklist
  • Tests cover the new/changed behavior
  • 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, #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
@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Mar 26, 2026
@zed-codeowner-coordinator zed-codeowner-coordinator Bot requested review from a team, as-cii and dinocosta and removed request for a team March 26, 2026 22:07
@zed-community-bot zed-community-bot Bot added the first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions label Mar 26, 2026
@maxdeviant maxdeviant changed the title Editor fix renamed file stale session path Mar 26, 2026
@saberoueslati
Copy link
Copy Markdown
Contributor Author

@ChristopherBiscardi can you activate the CI/CD pipeline for this PR ? Thank you

Copy link
Copy Markdown
Contributor

@ChristopherBiscardi ChristopherBiscardi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This does indeed fix the issue

@ChristopherBiscardi ChristopherBiscardi merged commit 1cd3249 into zed-industries:main Apr 15, 2026
31 checks passed
G36maid pushed a commit to G36maid/zed that referenced this pull request Apr 29, 2026
## 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 zed-industries#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, zed-industries#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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions

3 participants