mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-08 07:35:01 +03:00
Create valid disjoint selection sets in selections_in_ranges
This commit is contained in:
parent
efc85d1b75
commit
f3cd710f21
@ -1487,25 +1487,28 @@ impl Buffer {
|
||||
let mut ranges = ranges.into_iter().collect::<Vec<_>>();
|
||||
ranges.sort_unstable_by_key(|range| range.start);
|
||||
|
||||
let mut selections = Vec::with_capacity(ranges.len());
|
||||
for range in ranges {
|
||||
let mut selections = Vec::<Selection<usize>>::with_capacity(ranges.len());
|
||||
for mut range in ranges {
|
||||
let mut reversed = false;
|
||||
if range.start > range.end {
|
||||
selections.push(Selection {
|
||||
id: NEXT_SELECTION_ID.fetch_add(1, atomic::Ordering::SeqCst),
|
||||
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,
|
||||
});
|
||||
reversed = true;
|
||||
std::mem::swap(&mut range.start, &mut range.end);
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
@ -3323,7 +3323,7 @@ mod tests {
|
||||
|
||||
#[gpui::test]
|
||||
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;
|
||||
|
||||
let initial_contents = "aaa\nbbbbb\nc\n";
|
||||
|
Loading…
Reference in New Issue
Block a user