mirror of
https://github.com/zed-industries/zed.git
synced 2026-12-02 13:30:26 +01:00
editor: Expand excerpts from deleted diff hunks (#63946)
# Objective Fixes #62278. Allow `editor: expand excerpts` from deleted text in unified diffs. ## Solution - Resolve cursor and selection ranges against the current snapshot, including deleted hunks. - Preserve half-open selection boundaries and include trailing empty excerpts at EOF. - Skip removed paths during expansion. ## Testing Regression coverage includes deleted-hunk cursors and selections, stale paths, selections ending at excerpt boundaries, and trailing empty excerpts. The boundary and EOF cases cover all three expansion directions. The Bookmarks action case uses `excerpt_context_lines: 0`. The new boundary and EOF regressions failed before the fix and passed afterward. - `cargo test --locked -p editor -p multi_buffer --lib`: 1026 editor tests and 67 multibuffer tests passed; 1 ignored. - `./script/clippy -p editor -p multi_buffer`: passed. - `cargo fmt --all -- --check`: passed. - `git diff --check origin/main..HEAD`: passed. Automated testing ran on Linux. The first full run hit a SQLite table lock in `persistence::tests::test_save_and_get_serialized_editor`. The isolated test and full rerun passed. ## Self-Review Checklist: - [x] I have reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks, if any, have justifying comments - [x] The content adheres to Zed UI standards - [x] Tests cover the new behavior - [x] Performance impact has been considered and is acceptable Release Notes: - Fixed excerpt expansion when the selection is on deleted text in unified diffs --------- Co-authored-by: Kirill Bulatov <kirill@zed.dev>
This commit is contained in:
@@ -3774,10 +3774,18 @@ impl MultiBufferSnapshot {
|
||||
cursor.seek(&start);
|
||||
|
||||
std::iter::from_fn(move || {
|
||||
let region = cursor.region()?;
|
||||
if region.range.start > end {
|
||||
return None;
|
||||
}
|
||||
let Some(region) = cursor.region().filter(|region| {
|
||||
region.range.start < end || (region.range.start == end && start == end)
|
||||
}) else {
|
||||
let excerpt = cursor.excerpt()?;
|
||||
if excerpt.text_summary.len != 0 || end != self.len() {
|
||||
return None;
|
||||
}
|
||||
let buffer = excerpt.buffer_snapshot(self);
|
||||
let offset = BufferOffset(excerpt.range.context.start.to_offset(buffer));
|
||||
cursor.next_excerpt();
|
||||
return Some((buffer, offset..offset, None));
|
||||
};
|
||||
let start_overshoot = start.saturating_sub(region.range.start);
|
||||
let end_overshoot = end.saturating_sub(region.range.start);
|
||||
let start = region
|
||||
|
||||
Reference in New Issue
Block a user