Fix opening excerpt when the cursor is at the end of a multi-buffer
This was caused by seeking with a right bias, which in the case of the last excerpt in the buffer would seek past the end of the buffer. This commit changes the behavior to move the cursor back to the previous excerpt if we overshoot, to ensure we always land on an excerpt.
This commit is contained in:
parent
8f49552121
commit
2a8e0824a6
1 changed files with 9 additions and 2 deletions
|
@ -1140,6 +1140,10 @@ impl MultiBuffer {
|
||||||
let mut result = Vec::new();
|
let mut result = Vec::new();
|
||||||
let mut cursor = snapshot.excerpts.cursor::<usize>();
|
let mut cursor = snapshot.excerpts.cursor::<usize>();
|
||||||
cursor.seek(&start, Bias::Right, &());
|
cursor.seek(&start, Bias::Right, &());
|
||||||
|
if cursor.item().is_none() {
|
||||||
|
cursor.prev(&());
|
||||||
|
}
|
||||||
|
|
||||||
while let Some(excerpt) = cursor.item() {
|
while let Some(excerpt) = cursor.item() {
|
||||||
if *cursor.start() > end {
|
if *cursor.start() > end {
|
||||||
break;
|
break;
|
||||||
|
@ -5072,16 +5076,19 @@ mod tests {
|
||||||
.read(cx)
|
.read(cx)
|
||||||
.range_to_buffer_ranges(start_ix..end_ix, cx);
|
.range_to_buffer_ranges(start_ix..end_ix, cx);
|
||||||
let excerpted_buffers_text = excerpted_buffer_ranges
|
let excerpted_buffers_text = excerpted_buffer_ranges
|
||||||
.into_iter()
|
.iter()
|
||||||
.map(|(buffer, buffer_range)| {
|
.map(|(buffer, buffer_range)| {
|
||||||
buffer
|
buffer
|
||||||
.read(cx)
|
.read(cx)
|
||||||
.text_for_range(buffer_range)
|
.text_for_range(buffer_range.clone())
|
||||||
.collect::<String>()
|
.collect::<String>()
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join("\n");
|
.join("\n");
|
||||||
assert_eq!(excerpted_buffers_text, text_for_range);
|
assert_eq!(excerpted_buffers_text, text_for_range);
|
||||||
|
if !expected_excerpts.is_empty() {
|
||||||
|
assert!(!excerpted_buffer_ranges.is_empty());
|
||||||
|
}
|
||||||
|
|
||||||
let expected_summary = TextSummary::from(&expected_text[start_ix..end_ix]);
|
let expected_summary = TextSummary::from(&expected_text[start_ix..end_ix]);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue