Fix push_excerpts_with_context_lines
when ranges overlap
This commit is contained in:
parent
9749fea705
commit
9ea535986f
1 changed files with 15 additions and 4 deletions
|
@ -617,7 +617,7 @@ impl MultiBuffer {
|
||||||
while let Some(next_range) = range_iter.peek() {
|
while let Some(next_range) = range_iter.peek() {
|
||||||
if next_range.start.row <= excerpt_end.row + context_line_count {
|
if next_range.start.row <= excerpt_end.row + context_line_count {
|
||||||
excerpt_end =
|
excerpt_end =
|
||||||
Point::new(range.end.row + 1 + context_line_count, 0).min(max_point);
|
Point::new(next_range.end.row + 1 + context_line_count, 0).min(max_point);
|
||||||
ranges_in_excerpt += 1;
|
ranges_in_excerpt += 1;
|
||||||
range_iter.next();
|
range_iter.next();
|
||||||
} else {
|
} else {
|
||||||
|
@ -2918,14 +2918,13 @@ mod tests {
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
fn test_excerpts_with_context_lines(cx: &mut MutableAppContext) {
|
fn test_excerpts_with_context_lines(cx: &mut MutableAppContext) {
|
||||||
let buffer = cx.add_model(|cx| Buffer::new(0, sample_text(20, 3, 'a'), cx));
|
let buffer = cx.add_model(|cx| Buffer::new(0, sample_text(20, 3, 'a'), cx));
|
||||||
|
|
||||||
let multibuffer = cx.add_model(|_| MultiBuffer::new(0));
|
let multibuffer = cx.add_model(|_| MultiBuffer::new(0));
|
||||||
let anchor_ranges = multibuffer.update(cx, |multibuffer, cx| {
|
let anchor_ranges = multibuffer.update(cx, |multibuffer, cx| {
|
||||||
multibuffer.push_excerpts_with_context_lines(
|
multibuffer.push_excerpts_with_context_lines(
|
||||||
buffer.clone(),
|
buffer.clone(),
|
||||||
vec![
|
vec![
|
||||||
Point::new(3, 2)..Point::new(4, 2),
|
Point::new(3, 2)..Point::new(4, 2),
|
||||||
Point::new(7, 3)..Point::new(7, 1),
|
Point::new(7, 1)..Point::new(7, 3),
|
||||||
Point::new(15, 0)..Point::new(15, 0),
|
Point::new(15, 0)..Point::new(15, 0),
|
||||||
],
|
],
|
||||||
2,
|
2,
|
||||||
|
@ -2936,7 +2935,19 @@ mod tests {
|
||||||
let snapshot = multibuffer.read(cx).snapshot(cx);
|
let snapshot = multibuffer.read(cx).snapshot(cx);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
snapshot.text(),
|
snapshot.text(),
|
||||||
"bbb\nccc\nddd\neee\nfff\nggg\n\nnnn\nooo\nppp\nqqq\nrrr\n"
|
"bbb\nccc\nddd\neee\nfff\nggg\nhhh\niii\njjj\n\nnnn\nooo\nppp\nqqq\nrrr\n"
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
anchor_ranges
|
||||||
|
.iter()
|
||||||
|
.map(|range| range.to_point(&snapshot))
|
||||||
|
.collect::<Vec<_>>(),
|
||||||
|
vec![
|
||||||
|
Point::new(2, 2)..Point::new(3, 2),
|
||||||
|
Point::new(6, 1)..Point::new(6, 3),
|
||||||
|
Point::new(12, 0)..Point::new(12, 0)
|
||||||
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue