Preserve cursor position when resetting excerpts (#27850)

Release Notes:

- N/A

---------

Co-authored-by: Nathan Sobo <nathan@zed.dev>
Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
This commit is contained in:
Antonio Scandurra 2025-04-01 18:55:10 +02:00 committed by GitHub
parent f859b328f0
commit 76871056f5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 299 additions and 617 deletions

View file

@ -3165,18 +3165,12 @@ fn test_indent_outdent_with_excerpts(cx: &mut TestAppContext) {
let mut multibuffer = MultiBuffer::new(ReadWrite);
multibuffer.push_excerpts(
toml_buffer.clone(),
[ExcerptRange {
context: Point::new(0, 0)..Point::new(2, 0),
primary: None,
}],
[ExcerptRange::new(Point::new(0, 0)..Point::new(2, 0))],
cx,
);
multibuffer.push_excerpts(
rust_buffer.clone(),
[ExcerptRange {
context: Point::new(0, 0)..Point::new(1, 0),
primary: None,
}],
[ExcerptRange::new(Point::new(0, 0)..Point::new(1, 0))],
cx,
);
multibuffer
@ -7859,54 +7853,27 @@ async fn test_multibuffer_format_during_save(cx: &mut TestAppContext) {
multi_buffer.push_excerpts(
buffer_1.clone(),
[
ExcerptRange {
context: Point::new(0, 0)..Point::new(3, 0),
primary: None,
},
ExcerptRange {
context: Point::new(5, 0)..Point::new(7, 0),
primary: None,
},
ExcerptRange {
context: Point::new(9, 0)..Point::new(10, 4),
primary: None,
},
ExcerptRange::new(Point::new(0, 0)..Point::new(3, 0)),
ExcerptRange::new(Point::new(5, 0)..Point::new(7, 0)),
ExcerptRange::new(Point::new(9, 0)..Point::new(10, 4)),
],
cx,
);
multi_buffer.push_excerpts(
buffer_2.clone(),
[
ExcerptRange {
context: Point::new(0, 0)..Point::new(3, 0),
primary: None,
},
ExcerptRange {
context: Point::new(5, 0)..Point::new(7, 0),
primary: None,
},
ExcerptRange {
context: Point::new(9, 0)..Point::new(10, 4),
primary: None,
},
ExcerptRange::new(Point::new(0, 0)..Point::new(3, 0)),
ExcerptRange::new(Point::new(5, 0)..Point::new(7, 0)),
ExcerptRange::new(Point::new(9, 0)..Point::new(10, 4)),
],
cx,
);
multi_buffer.push_excerpts(
buffer_3.clone(),
[
ExcerptRange {
context: Point::new(0, 0)..Point::new(3, 0),
primary: None,
},
ExcerptRange {
context: Point::new(5, 0)..Point::new(7, 0),
primary: None,
},
ExcerptRange {
context: Point::new(9, 0)..Point::new(10, 4),
primary: None,
},
ExcerptRange::new(Point::new(0, 0)..Point::new(3, 0)),
ExcerptRange::new(Point::new(5, 0)..Point::new(7, 0)),
ExcerptRange::new(Point::new(9, 0)..Point::new(10, 4)),
],
cx,
);
@ -10685,14 +10652,8 @@ fn test_editing_disjoint_excerpts(cx: &mut TestAppContext) {
multibuffer.push_excerpts(
buffer.clone(),
[
ExcerptRange {
context: Point::new(0, 0)..Point::new(0, 4),
primary: None,
},
ExcerptRange {
context: Point::new(1, 0)..Point::new(1, 4),
primary: None,
},
ExcerptRange::new(Point::new(0, 0)..Point::new(0, 4)),
ExcerptRange::new(Point::new(1, 0)..Point::new(1, 4)),
],
cx,
);
@ -10758,10 +10719,7 @@ fn test_editing_overlapping_excerpts(cx: &mut TestAppContext) {
);
let excerpt_ranges = markers.into_iter().map(|marker| {
let context = excerpt_ranges.remove(&marker).unwrap()[0].clone();
ExcerptRange {
context,
primary: None,
}
ExcerptRange::new(context.clone())
});
let buffer = cx.new(|cx| Buffer::local(initial_text, cx));
let multibuffer = cx.new(|cx| {
@ -10829,14 +10787,8 @@ fn test_refresh_selections(cx: &mut TestAppContext) {
.push_excerpts(
buffer.clone(),
[
ExcerptRange {
context: Point::new(0, 0)..Point::new(1, 4),
primary: None,
},
ExcerptRange {
context: Point::new(1, 0)..Point::new(2, 4),
primary: None,
},
ExcerptRange::new(Point::new(0, 0)..Point::new(1, 4)),
ExcerptRange::new(Point::new(1, 0)..Point::new(2, 4)),
],
cx,
)
@ -10920,14 +10872,8 @@ fn test_refresh_selections_while_selecting_with_mouse(cx: &mut TestAppContext) {
.push_excerpts(
buffer.clone(),
[
ExcerptRange {
context: Point::new(0, 0)..Point::new(1, 4),
primary: None,
},
ExcerptRange {
context: Point::new(1, 0)..Point::new(2, 4),
primary: None,
},
ExcerptRange::new(Point::new(0, 0)..Point::new(1, 4)),
ExcerptRange::new(Point::new(1, 0)..Point::new(2, 4)),
],
cx,
)
@ -11398,34 +11344,16 @@ async fn test_following_with_multiple_excerpts(cx: &mut TestAppContext) {
let excerpt_ids = multibuffer.push_excerpts(
buffer_1.clone(),
[
ExcerptRange {
context: 1..6,
primary: None,
},
ExcerptRange {
context: 12..15,
primary: None,
},
ExcerptRange {
context: 0..3,
primary: None,
},
ExcerptRange::new(1..6),
ExcerptRange::new(12..15),
ExcerptRange::new(0..3),
],
cx,
);
multibuffer.insert_excerpts_after(
excerpt_ids[0],
buffer_2.clone(),
[
ExcerptRange {
context: 8..12,
primary: None,
},
ExcerptRange {
context: 0..6,
primary: None,
},
],
[ExcerptRange::new(8..12), ExcerptRange::new(0..6)],
cx,
);
});
@ -13599,54 +13527,27 @@ async fn test_multibuffer_reverts(cx: &mut TestAppContext) {
multibuffer.push_excerpts(
buffer_1.clone(),
[
ExcerptRange {
context: Point::new(0, 0)..Point::new(3, 0),
primary: None,
},
ExcerptRange {
context: Point::new(5, 0)..Point::new(7, 0),
primary: None,
},
ExcerptRange {
context: Point::new(9, 0)..Point::new(10, 4),
primary: None,
},
ExcerptRange::new(Point::new(0, 0)..Point::new(3, 0)),
ExcerptRange::new(Point::new(5, 0)..Point::new(7, 0)),
ExcerptRange::new(Point::new(9, 0)..Point::new(10, 4)),
],
cx,
);
multibuffer.push_excerpts(
buffer_2.clone(),
[
ExcerptRange {
context: Point::new(0, 0)..Point::new(3, 0),
primary: None,
},
ExcerptRange {
context: Point::new(5, 0)..Point::new(7, 0),
primary: None,
},
ExcerptRange {
context: Point::new(9, 0)..Point::new(10, 4),
primary: None,
},
ExcerptRange::new(Point::new(0, 0)..Point::new(3, 0)),
ExcerptRange::new(Point::new(5, 0)..Point::new(7, 0)),
ExcerptRange::new(Point::new(9, 0)..Point::new(10, 4)),
],
cx,
);
multibuffer.push_excerpts(
buffer_3.clone(),
[
ExcerptRange {
context: Point::new(0, 0)..Point::new(3, 0),
primary: None,
},
ExcerptRange {
context: Point::new(5, 0)..Point::new(7, 0),
primary: None,
},
ExcerptRange {
context: Point::new(9, 0)..Point::new(10, 4),
primary: None,
},
ExcerptRange::new(Point::new(0, 0)..Point::new(3, 0)),
ExcerptRange::new(Point::new(5, 0)..Point::new(7, 0)),
ExcerptRange::new(Point::new(9, 0)..Point::new(10, 4)),
],
cx,
);
@ -13766,54 +13667,27 @@ async fn test_mutlibuffer_in_navigation_history(cx: &mut TestAppContext) {
multibuffer.push_excerpts(
buffer_1.clone(),
[
ExcerptRange {
context: Point::new(0, 0)..Point::new(3, 0),
primary: None,
},
ExcerptRange {
context: Point::new(5, 0)..Point::new(7, 0),
primary: None,
},
ExcerptRange {
context: Point::new(9, 0)..Point::new(10, 4),
primary: None,
},
ExcerptRange::new(Point::new(0, 0)..Point::new(3, 0)),
ExcerptRange::new(Point::new(5, 0)..Point::new(7, 0)),
ExcerptRange::new(Point::new(9, 0)..Point::new(10, 4)),
],
cx,
);
multibuffer.push_excerpts(
buffer_2.clone(),
[
ExcerptRange {
context: Point::new(0, 0)..Point::new(3, 0),
primary: None,
},
ExcerptRange {
context: Point::new(5, 0)..Point::new(7, 0),
primary: None,
},
ExcerptRange {
context: Point::new(9, 0)..Point::new(10, 4),
primary: None,
},
ExcerptRange::new(Point::new(0, 0)..Point::new(3, 0)),
ExcerptRange::new(Point::new(5, 0)..Point::new(7, 0)),
ExcerptRange::new(Point::new(9, 0)..Point::new(10, 4)),
],
cx,
);
multibuffer.push_excerpts(
buffer_3.clone(),
[
ExcerptRange {
context: Point::new(0, 0)..Point::new(3, 0),
primary: None,
},
ExcerptRange {
context: Point::new(5, 0)..Point::new(7, 0),
primary: None,
},
ExcerptRange {
context: Point::new(9, 0)..Point::new(10, 4),
primary: None,
},
ExcerptRange::new(Point::new(0, 0)..Point::new(3, 0)),
ExcerptRange::new(Point::new(5, 0)..Point::new(7, 0)),
ExcerptRange::new(Point::new(9, 0)..Point::new(10, 4)),
],
cx,
);
@ -14266,54 +14140,27 @@ async fn test_toggle_diff_expand_in_multi_buffer(cx: &mut TestAppContext) {
multibuffer.push_excerpts(
buffer_1.clone(),
[
ExcerptRange {
context: Point::new(0, 0)..Point::new(3, 0),
primary: None,
},
ExcerptRange {
context: Point::new(5, 0)..Point::new(7, 0),
primary: None,
},
ExcerptRange {
context: Point::new(9, 0)..Point::new(10, 3),
primary: None,
},
ExcerptRange::new(Point::new(0, 0)..Point::new(3, 0)),
ExcerptRange::new(Point::new(5, 0)..Point::new(7, 0)),
ExcerptRange::new(Point::new(9, 0)..Point::new(10, 3)),
],
cx,
);
multibuffer.push_excerpts(
buffer_2.clone(),
[
ExcerptRange {
context: Point::new(0, 0)..Point::new(3, 0),
primary: None,
},
ExcerptRange {
context: Point::new(5, 0)..Point::new(7, 0),
primary: None,
},
ExcerptRange {
context: Point::new(9, 0)..Point::new(10, 3),
primary: None,
},
ExcerptRange::new(Point::new(0, 0)..Point::new(3, 0)),
ExcerptRange::new(Point::new(5, 0)..Point::new(7, 0)),
ExcerptRange::new(Point::new(9, 0)..Point::new(10, 3)),
],
cx,
);
multibuffer.push_excerpts(
buffer_3.clone(),
[
ExcerptRange {
context: Point::new(0, 0)..Point::new(3, 0),
primary: None,
},
ExcerptRange {
context: Point::new(5, 0)..Point::new(7, 0),
primary: None,
},
ExcerptRange {
context: Point::new(9, 0)..Point::new(10, 3),
primary: None,
},
ExcerptRange::new(Point::new(0, 0)..Point::new(3, 0)),
ExcerptRange::new(Point::new(5, 0)..Point::new(7, 0)),
ExcerptRange::new(Point::new(9, 0)..Point::new(10, 3)),
],
cx,
);
@ -14422,18 +14269,9 @@ async fn test_expand_diff_hunk_at_excerpt_boundary(cx: &mut TestAppContext) {
multibuffer.push_excerpts(
buffer.clone(),
[
ExcerptRange {
context: Point::new(0, 0)..Point::new(2, 0),
primary: None,
},
ExcerptRange {
context: Point::new(4, 0)..Point::new(7, 0),
primary: None,
},
ExcerptRange {
context: Point::new(9, 0)..Point::new(10, 0),
primary: None,
},
ExcerptRange::new(Point::new(0, 0)..Point::new(2, 0)),
ExcerptRange::new(Point::new(4, 0)..Point::new(7, 0)),
ExcerptRange::new(Point::new(9, 0)..Point::new(10, 0)),
],
cx,
);
@ -16613,54 +16451,27 @@ async fn test_folding_buffers(cx: &mut TestAppContext) {
multi_buffer.push_excerpts(
buffer_1.clone(),
[
ExcerptRange {
context: Point::new(0, 0)..Point::new(3, 0),
primary: None,
},
ExcerptRange {
context: Point::new(5, 0)..Point::new(7, 0),
primary: None,
},
ExcerptRange {
context: Point::new(9, 0)..Point::new(10, 4),
primary: None,
},
ExcerptRange::new(Point::new(0, 0)..Point::new(3, 0)),
ExcerptRange::new(Point::new(5, 0)..Point::new(7, 0)),
ExcerptRange::new(Point::new(9, 0)..Point::new(10, 4)),
],
cx,
);
multi_buffer.push_excerpts(
buffer_2.clone(),
[
ExcerptRange {
context: Point::new(0, 0)..Point::new(3, 0),
primary: None,
},
ExcerptRange {
context: Point::new(5, 0)..Point::new(7, 0),
primary: None,
},
ExcerptRange {
context: Point::new(9, 0)..Point::new(10, 4),
primary: None,
},
ExcerptRange::new(Point::new(0, 0)..Point::new(3, 0)),
ExcerptRange::new(Point::new(5, 0)..Point::new(7, 0)),
ExcerptRange::new(Point::new(9, 0)..Point::new(10, 4)),
],
cx,
);
multi_buffer.push_excerpts(
buffer_3.clone(),
[
ExcerptRange {
context: Point::new(0, 0)..Point::new(3, 0),
primary: None,
},
ExcerptRange {
context: Point::new(5, 0)..Point::new(7, 0),
primary: None,
},
ExcerptRange {
context: Point::new(9, 0)..Point::new(10, 4),
primary: None,
},
ExcerptRange::new(Point::new(0, 0)..Point::new(3, 0)),
ExcerptRange::new(Point::new(5, 0)..Point::new(7, 0)),
ExcerptRange::new(Point::new(9, 0)..Point::new(10, 4)),
],
cx,
);
@ -16807,26 +16618,17 @@ async fn test_folding_buffers_with_one_excerpt(cx: &mut TestAppContext) {
let mut multi_buffer = MultiBuffer::new(ReadWrite);
multi_buffer.push_excerpts(
buffer_1.clone(),
[ExcerptRange {
context: Point::new(0, 0)..Point::new(3, 0),
primary: None,
}],
[ExcerptRange::new(Point::new(0, 0)..Point::new(3, 0))],
cx,
);
multi_buffer.push_excerpts(
buffer_2.clone(),
[ExcerptRange {
context: Point::new(0, 0)..Point::new(3, 0),
primary: None,
}],
[ExcerptRange::new(Point::new(0, 0)..Point::new(3, 0))],
cx,
);
multi_buffer.push_excerpts(
buffer_3.clone(),
[ExcerptRange {
context: Point::new(0, 0)..Point::new(3, 0),
primary: None,
}],
[ExcerptRange::new(Point::new(0, 0)..Point::new(3, 0))],
cx,
);
multi_buffer
@ -16939,14 +16741,13 @@ async fn test_folding_buffer_when_multibuffer_has_only_one_excerpt(cx: &mut Test
let mut multi_buffer = MultiBuffer::new(ReadWrite);
multi_buffer.push_excerpts(
buffer_1.clone(),
[ExcerptRange {
context: Point::new(0, 0)
[ExcerptRange::new(
Point::new(0, 0)
..Point::new(
sample_text.chars().filter(|&c| c == '\n').count() as u32 + 1,
0,
),
primary: None,
}],
)],
cx,
);
multi_buffer