@@ -269,6 +269,25 @@ impl Selection {
269 pub fn fragments<'a>(&'a self, text: RopeSlice<'a>) -> impl Iterator<Item = Cow<str>> + 'a {
269 pub fn fragments<'a>(&'a self, text: RopeSlice<'a>) -> impl Iterator<Item = Cow<str>> + 'a {
270 self.ranges.iter().map(move |range| range.fragment(text))
270 self.ranges.iter().map(move |range| range.fragment(text))
274+ pub fn iter(&self) -> std::slice::Iter<'_, Range> {
279+ pub fn len(&self) -> usize {
284+impl<'a> IntoIterator for &'a Selection {
285+ type Item = &'a Range;
286+ type IntoIter = std::slice::Iter<'a, Range>;
288+ fn into_iter(self) -> std::slice::Iter<'a, Range> {
289+ self.ranges().iter()
274// TODO: checkSelection -> check if valid for doc length
293// TODO: checkSelection -> check if valid for doc length
@@ -279,7 +298,6 @@ pub fn keep_matches(
279 regex: &crate::regex::Regex,
298 regex: &crate::regex::Regex,
280) -> Option<Selection> {
299) -> Option<Selection> {
281 let result: SmallVec<_> = selection
300 let result: SmallVec<_> = selection
284 .filter(|range| regex.is_match(&range.fragment(text)))
302 .filter(|range| regex.is_match(&range.fragment(text)))
285 .copied()
303 .copied()
@@ -297,9 +315,9 @@ pub fn select_on_matches(
297 selection: &Selection,
315 selection: &Selection,
298 regex: &crate::regex::Regex,
316 regex: &crate::regex::Regex,
299) -> Option<Selection> {
317) -> Option<Selection> {
300− let mut result = SmallVec::with_capacity(selection.ranges().len());
318+ let mut result = SmallVec::with_capacity(selection.len());
302− for sel in selection.ranges() {
320+ for sel in selection {
303 // TODO: can't avoid occasional allocations since Regex can't operate on chunks yet
321 // TODO: can't avoid occasional allocations since Regex can't operate on chunks yet
304 let fragment = sel.fragment(text);
322 let fragment = sel.fragment(text);
@@ -331,9 +349,9 @@ pub fn split_on_matches(
331 selection: &Selection,
349 selection: &Selection,
332 regex: &crate::regex::Regex,
350 regex: &crate::regex::Regex,
333) -> Selection {
351) -> Selection {
334− let mut result = SmallVec::with_capacity(selection.ranges().len());
352+ let mut result = SmallVec::with_capacity(selection.len());
336− for sel in selection.ranges() {
354+ for sel in selection {
337 // TODO: can't avoid occasional allocations since Regex can't operate on chunks yet
355 // TODO: can't avoid occasional allocations since Regex can't operate on chunks yet
338 let fragment = sel.fragment(text);
356 let fragment = sel.fragment(text);