aboutsummaryrefslogtreecommitdiff
path: root/helix-core
diff options
context:
space:
mode:
authorMichael Davis2023-07-10 21:43:16 +0000
committerBlaž Hrastnik2023-07-31 06:05:38 +0000
commitda2afe7353066743e30592f03a7a55f24df4dd5c (patch)
treead8bd23402b1e9675e8eb4dd3a0fdf591883c8ba /helix-core
parent5eb1a25d8a0aeb202358b5b5a3b44bb5f43eced6 (diff)
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.
Diffstat (limited to 'helix-core')
-rw-r--r--helix-core/src/selection.rs12
1 files changed, 10 insertions, 2 deletions
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<Item = Cow<str>> + 'a {
+ pub fn fragments<'a>(
+ &'a self,
+ text: RopeSlice<'a>,
+ ) -> impl DoubleEndedIterator<Item = Cow<'a, str>> + ExactSizeIterator<Item = Cow<str>> + 'a
+ {
self.ranges.iter().map(move |range| range.fragment(text))
}
- pub fn slices<'a>(&'a self, text: RopeSlice<'a>) -> impl Iterator<Item = RopeSlice> + 'a {
+ pub fn slices<'a>(
+ &'a self,
+ text: RopeSlice<'a>,
+ ) -> impl DoubleEndedIterator<Item = RopeSlice<'a>> + ExactSizeIterator<Item = RopeSlice<'a>> + 'a
+ {
self.ranges.iter().map(move |range| range.slice(text))
}