Files
Stiven Gjekaj da294762d6 editor: Fix crash after moving a project with a split diff to a new window (#67128)
## Summary

Fixes #66688.

When splitting, the RHS display map has a weak reference to the LHS
display map. If the RHS editor outlives the `SplittableEditor`, the LHS
display map will be deallocated. However, the scroll anchor may still
refer to it. This leads to a panic in `ScrollManager::native_anchor` at
line `scroll.rs:242`.

This PR ensures that the same clean-up as in `unsplit` occurs when the
`SplittableEditor` is released. The first commit refactors this clean-up
into a function that takes a `&mut App`. The second commit adds this
function to an `on_release` handler.

We choose to do clean-up on release rather than adding fallback logic in
`native_anchor`, as it removes the stale state in its source. Fallback
logic can be added if desired.

## Testing

- Added test case `test_rhs_editor_outlives_released_split`. This
scrolls within the LHS, releases the split editor, ensures that the RHS
editor lives longer, and attempts to get the native anchor. Before this
change, this test panics with the error given in the issue. After this
change, the test passes.
- All tests pass in `cargo test -p editor` (1235).
- No clippy warnings in `./script/clippy -p editor`.
- Manually tested on macOS.

### How to test

Within a window:

1. Have two projects open in the sidebar.
2. In one project, with uncommitted changes, run `git: diff`, then open
in split mode with `editor: toggle split diff`.
3. Scroll in the left pane.
4. Move the project into a new window with `workspace: move project to
new window` (or "Open Project in New Window" from the project's menu in
the sidebar).
5. Change the theme with `theme selector: toggle`.

On main, Zed will panic here. With this change, no problem occurs.

## Self-review

- [x] Checked diff for quality, security, reliability and performance.
- [ ] UI change checklist followed (if any)
https://zed.dev/docs/development/ui-checklist. (N/A, no UI changes)
- [x] Test(s) added to cover new/changed behaviour.

Release Notes:

- Fixed a panic when moving a project with a split diff to a new window.

---------

Co-authored-by: Smit Barmase <heysmitbarmase@gmail.com>
2026-11-18 11:42:50 +00:00
..