From fc2251e7ed2fbf2062846ce782d7e3985aecc61f Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Wed, 29 Nov 2023 12:41:22 -0800 Subject: [PATCH] Implement SelectionsCollection::select_anchor_ranges --- crates/editor2/src/selections_collection.rs | 51 +++++++++++---------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/crates/editor2/src/selections_collection.rs b/crates/editor2/src/selections_collection.rs index bcf41f135b..6542ace5fb 100644 --- a/crates/editor2/src/selections_collection.rs +++ b/crates/editor2/src/selections_collection.rs @@ -595,31 +595,32 @@ impl<'a> MutableSelectionsCollection<'a> { self.select(selections) } - pub fn select_anchor_ranges>>(&mut self, ranges: I) { - todo!() - // let buffer = self.buffer.read(self.cx).snapshot(self.cx); - // let selections = ranges - // .into_iter() - // .map(|range| { - // let mut start = range.start; - // let mut end = range.end; - // let reversed = if start.cmp(&end, &buffer).is_gt() { - // mem::swap(&mut start, &mut end); - // true - // } else { - // false - // }; - // Selection { - // id: post_inc(&mut self.collection.next_selection_id), - // start, - // end, - // reversed, - // goal: SelectionGoal::None, - // } - // }) - // .collect::>(); - - // self.select_anchors(selections) + pub fn select_anchor_ranges(&mut self, ranges: I) + where + I: IntoIterator>, + { + let buffer = self.buffer.read(self.cx).snapshot(self.cx); + let selections = ranges + .into_iter() + .map(|range| { + let mut start = range.start; + let mut end = range.end; + let reversed = if start.cmp(&end, &buffer).is_gt() { + mem::swap(&mut start, &mut end); + true + } else { + false + }; + Selection { + id: post_inc(&mut self.collection.next_selection_id), + start, + end, + reversed, + goal: SelectionGoal::None, + } + }) + .collect::>(); + self.select_anchors(selections) } pub fn new_selection_id(&mut self) -> usize {