From da2afe7353066743e30592f03a7a55f24df4dd5c Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Mon, 10 Jul 2023 16:43:16 -0500 Subject: Add '#' and '.' special registers These come from Kakoune: * '#' is the selection index register. It's read-only and produces the selection index numbers, 1-indexed. * '.' is the selection contents register. It is also read-only and mirrors the contents of the current selections when read. We switch the iterators returned from Selection's `fragments` and `slices` methods to ExactSizeIterators because: * The selection contents register can simply return the fragments iterator. * ExactSizeIterator is already implemented for iterators over Vecs, so it's essentially free. * The `len` method can be useful on its own. --- helix-core/src/selection.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'helix-core') diff --git a/helix-core/src/selection.rs b/helix-core/src/selection.rs index 9104c209..c44685ee 100644 --- a/helix-core/src/selection.rs +++ b/helix-core/src/selection.rs @@ -630,11 +630,19 @@ impl Selection { self.transform(|range| Range::point(range.cursor(text))) } - pub fn fragments<'a>(&'a self, text: RopeSlice<'a>) -> impl Iterator> + 'a { + pub fn fragments<'a>( + &'a self, + text: RopeSlice<'a>, + ) -> impl DoubleEndedIterator> + ExactSizeIterator> + 'a + { self.ranges.iter().map(move |range| range.fragment(text)) } - pub fn slices<'a>(&'a self, text: RopeSlice<'a>) -> impl Iterator + 'a { + pub fn slices<'a>( + &'a self, + text: RopeSlice<'a>, + ) -> impl DoubleEndedIterator> + ExactSizeIterator> + 'a + { self.ranges.iter().map(move |range| range.slice(text)) } -- cgit v1.2.3-70-g09d2