buffer_diff: Fix panic when staging hunks with stale buffer snapshot (#51641)

When the buffer is edited after the diff is computed but before staging,
anchor positions shift while diff_base_byte_range values don't. If the
primary (HEAD) hunk extends past the unstaged (index) hunk, an edit in
the extension region causes the overshoot calculation to produce an
index_end that exceeds index_text.len(), panicking in
rope::Cursor::suffix.

Fix by clamping index_end to index_text.len(). This is safe because the
computed index text is an optimistic approximation — the real staging
happens at the filesystem level via git add/git reset.

Closes ZED-5R2


Release Notes:

- Fixed a source of panics when staging diff hunks
ebd80d7995Lukas Wirth committed on 3/16/2026, 8:49:02 AM· committed by GitHubparenta93c66e
1 file changedLine totals unavailable