diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index c82a5d6d2ffeacbc9f2c39280f2d15f674b74ead..c663e442a773e601e78eb66d4134ce484acd8b6e 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -3049,35 +3049,50 @@ impl Editor { where D: 'a + TextDimension + Ord + Sub, { - // let buffer = self.buffer.read(cx).snapshot(cx); - // let mut selections = self.selection_set(cx).selections::(&buffer).peekable(); - // let mut pending_selection = self.pending_selection(cx); - - // iter::from_fn(move || { - // if let Some(pending) = pending_selection.as_mut() { - // while let Some(next_selection) = selections.peek() { - // if pending.start <= next_selection.end && pending.end >= next_selection.start { - // let next_selection = selections.next().unwrap(); - // if next_selection.start < pending.start { - // pending.start = next_selection.start; - // } - // if next_selection.end > pending.end { - // pending.end = next_selection.end; - // } - // } else if next_selection.end < pending.start { - // return selections.next(); - // } else { - // break; - // } - // } + let buffer = self.buffer.read(cx).snapshot(cx); - // pending_selection.take() - // } else { - // selections.next() - // } - // }) - // .collect() - todo!() + let mut summaries = buffer + .summaries_for_anchors::(self.selections.iter().flat_map(|s| [&s.start, &s.end])) + .into_iter(); + + let mut selections = self + .selections + .iter() + .map(|s| Selection { + id: s.id, + start: summaries.next().unwrap(), + end: summaries.next().unwrap(), + reversed: s.reversed, + goal: s.goal, + }) + .peekable(); + + let mut pending_selection = self.pending_selection::(&buffer, cx); + + iter::from_fn(move || { + if let Some(pending) = pending_selection.as_mut() { + while let Some(next_selection) = selections.peek() { + if pending.start <= next_selection.end && pending.end >= next_selection.start { + let next_selection = selections.next().unwrap(); + if next_selection.start < pending.start { + pending.start = next_selection.start; + } + if next_selection.end > pending.end { + pending.end = next_selection.end; + } + } else if next_selection.end < pending.start { + return selections.next(); + } else { + break; + } + } + + pending_selection.take() + } else { + selections.next() + } + }) + .collect() } fn pending_selection>( diff --git a/crates/editor/src/multi_buffer.rs b/crates/editor/src/multi_buffer.rs index 5f2ca98f8d6c3a675766cd94833bbc47f311b559..1e93c16f7779cba32509133c76c0430f5409bb7e 100644 --- a/crates/editor/src/multi_buffer.rs +++ b/crates/editor/src/multi_buffer.rs @@ -777,7 +777,7 @@ impl MultiBufferSnapshot { summary } - fn summary_for_anchor(&self, anchor: &Anchor) -> D + pub fn summary_for_anchor(&self, anchor: &Anchor) -> D where D: TextDimension + Ord + Sub, { @@ -798,7 +798,7 @@ impl MultiBufferSnapshot { D::from_text_summary(&cursor.start().text) } - fn summaries_for_anchors<'a, D, I>(&'a self, anchors: I) -> Vec + pub fn summaries_for_anchors<'a, D, I>(&'a self, anchors: I) -> Vec where D: TextDimension + Ord + Sub, I: 'a + IntoIterator,