Fix stale folded buffers in split diff view#49699
Merged
Conversation
When a buffer is removed from a multibuffer (via remove_excerpts_for_path), the block map's folded_buffers set retains a stale entry for that buffer. Later, when the split view syncs folded buffers from RHS to LHS, it tries to look up the companion mapping for this stale buffer ID and fails because the companion no longer has a mapping for a buffer that's no longer in the multibuffer. Previously this was an expect() that panicked; the prior commit turned it into a log::warn and skip. This commit goes further: instead of just skipping the unmapped buffer, we actively remove it from the RHS's folded_buffers set so it doesn't persist as stale state. This ensures that if the same buffer is later re-added to the multibuffer, it won't incorrectly appear as folded. The test is extended to cover this scenario: after removing a folded buffer and re-adding it via set_excerpts_for_path, both the LHS and RHS editors correctly report the buffer as not folded.
Member
|
/cherry-pick preview |
Member
|
/cherry-pick stable |
Contributor
|
🍒💥 Cherry-pick did not succeed |
Contributor
|
🍒💥 Cherry-pick did not succeed |
bennetbo
pushed a commit
that referenced
this pull request
Feb 20, 2026
When a buffer is folded in the split diff view and then removed from the multibuffer (via `remove_excerpts_for_path`), the block map's `folded_buffers` set retains a stale entry for that buffer ID. Later, when the split view syncs folded state from the RHS display map to the LHS, it tries to look up the companion mapping for this stale buffer and fails because the companion no longer tracks a buffer that's been removed from the multibuffer. This originally caused a panic via `.expect()`. This PR: 1. Converts the panic into graceful handling by skipping unmapped buffers. 2. Actively removes stale entries from `folded_buffers` so they don't persist as ghost state — ensuring that if the same buffer is later re-added, it won't incorrectly appear as folded. 3. Adds a regression test covering the full lifecycle: fold → remove → split → re-add → assert both LHS and RHS report the buffer as not folded. Release Notes: - Fixed a crash in split diff view when a folded buffer was removed and re-added.
bennetbo
pushed a commit
that referenced
this pull request
Feb 20, 2026
When a buffer is folded in the split diff view and then removed from the multibuffer (via `remove_excerpts_for_path`), the block map's `folded_buffers` set retains a stale entry for that buffer ID. Later, when the split view syncs folded state from the RHS display map to the LHS, it tries to look up the companion mapping for this stale buffer and fails because the companion no longer tracks a buffer that's been removed from the multibuffer. This originally caused a panic via `.expect()`. This PR: 1. Converts the panic into graceful handling by skipping unmapped buffers. 2. Actively removes stale entries from `folded_buffers` so they don't persist as ghost state — ensuring that if the same buffer is later re-added, it won't incorrectly appear as folded. 3. Adds a regression test covering the full lifecycle: fold → remove → split → re-add → assert both LHS and RHS report the buffer as not folded. Release Notes: - Fixed a crash in split diff view when a folded buffer was removed and re-added.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a buffer is folded in the split diff view and then removed from the multibuffer (via
remove_excerpts_for_path), the block map'sfolded_buffersset retains a stale entry for that buffer ID. Later, when the split view syncs folded state from the RHS display map to the LHS, it tries to look up the companion mapping for this stale buffer and fails because the companion no longer tracks a buffer that's been removed from the multibuffer.This originally caused a panic via
.expect(). This PR:folded_buffersso they don't persist as ghost state — ensuring that if the same buffer is later re-added, it won't incorrectly appear as folded.Release Notes: