Create valid disjoint selection sets in selections_in_ranges
This commit is contained in:
+20
-17
@@ -1487,25 +1487,28 @@ impl Buffer {
|
|||||||
let mut ranges = ranges.into_iter().collect::<Vec<_>>();
|
let mut ranges = ranges.into_iter().collect::<Vec<_>>();
|
||||||
ranges.sort_unstable_by_key(|range| range.start);
|
ranges.sort_unstable_by_key(|range| range.start);
|
||||||
|
|
||||||
let mut selections = Vec::with_capacity(ranges.len());
|
let mut selections = Vec::<Selection<usize>>::with_capacity(ranges.len());
|
||||||
for range in ranges {
|
for mut range in ranges {
|
||||||
|
let mut reversed = false;
|
||||||
if range.start > range.end {
|
if range.start > range.end {
|
||||||
selections.push(Selection {
|
reversed = true;
|
||||||
id: NEXT_SELECTION_ID.fetch_add(1, atomic::Ordering::SeqCst),
|
std::mem::swap(&mut range.start, &mut range.end);
|
||||||
start: range.end,
|
|
||||||
end: range.start,
|
|
||||||
reversed: true,
|
|
||||||
goal: SelectionGoal::None,
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
selections.push(Selection {
|
|
||||||
id: NEXT_SELECTION_ID.fetch_add(1, atomic::Ordering::SeqCst),
|
|
||||||
start: range.start,
|
|
||||||
end: range.end,
|
|
||||||
reversed: false,
|
|
||||||
goal: SelectionGoal::None,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(selection) = selections.last_mut() {
|
||||||
|
if selection.end >= range.start {
|
||||||
|
selection.end = range.end;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
selections.push(Selection {
|
||||||
|
id: NEXT_SELECTION_ID.fetch_add(1, atomic::Ordering::SeqCst),
|
||||||
|
start: range.start,
|
||||||
|
end: range.end,
|
||||||
|
reversed,
|
||||||
|
goal: SelectionGoal::None,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
Ok(selections)
|
Ok(selections)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3323,7 +3323,7 @@ mod tests {
|
|||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
async fn test_buffer_file_changes_on_disk(mut cx: gpui::TestAppContext) {
|
async fn test_buffer_file_changes_on_disk(mut cx: gpui::TestAppContext) {
|
||||||
use buffer::{Point, Selection, SelectionGoal, ToPoint};
|
use buffer::{Point, Selection, SelectionGoal};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
let initial_contents = "aaa\nbbbbb\nc\n";
|
let initial_contents = "aaa\nbbbbb\nc\n";
|
||||||
|
|||||||
Reference in New Issue
Block a user