@@ -273,14 +273,33 @@ impl Selection {
274// TODO: checkSelection -> check if valid for doc length
274// TODO: checkSelection -> check if valid for doc length
278+ selection: &Selection,
279+ regex: &crate::regex::Regex,
280+) -> Option<Selection> {
281+ let result: SmallVec<_> = selection
284+ .filter(|range| regex.is_match(&range.fragment(text)))
288+ // TODO: figure out a new primary index
289+ if !result.is_empty() {
290+ return Some(Selection::new(result, 0));
276pub fn select_on_matches(
295pub fn select_on_matches(
277 text: RopeSlice,
296 text: RopeSlice,
278− selections: &Selection,
297+ selection: &Selection,
279 regex: &crate::regex::Regex,
298 regex: &crate::regex::Regex,
280) -> Option<Selection> {
299) -> Option<Selection> {
281− let mut result = SmallVec::with_capacity(selections.ranges().len());
300+ let mut result = SmallVec::with_capacity(selection.ranges().len());
283− for sel in selections.ranges() {
302+ for sel in selection.ranges() {
284 // TODO: can't avoid occasional allocations since Regex can't operate on chunks yet
303 // TODO: can't avoid occasional allocations since Regex can't operate on chunks yet
285 let fragment = sel.fragment(text);
304 let fragment = sel.fragment(text);
@@ -309,12 +328,12 @@ pub fn select_on_matches(
309// TODO: support to split on capture #N instead of whole match
328// TODO: support to split on capture #N instead of whole match
310pub fn split_on_matches(
329pub fn split_on_matches(
311 text: RopeSlice,
330 text: RopeSlice,
312− selections: &Selection,
331+ selection: &Selection,
313 regex: &crate::regex::Regex,
332 regex: &crate::regex::Regex,
314) -> Selection {
333) -> Selection {
315− let mut result = SmallVec::with_capacity(selections.ranges().len());
334+ let mut result = SmallVec::with_capacity(selection.ranges().len());
317− for sel in selections.ranges() {
336+ for sel in selection.ranges() {
318 // TODO: can't avoid occasional allocations since Regex can't operate on chunks yet
337 // TODO: can't avoid occasional allocations since Regex can't operate on chunks yet
319 let fragment = sel.fragment(text);
338 let fragment = sel.fragment(text);
@@ -417,9 +436,9 @@ mod test {
418 let text = Rope::from("abcd efg wrs xyz 123 456");
437 let text = Rope::from("abcd efg wrs xyz 123 456");
420− let selections = Selection::new(smallvec![Range::new(0, 8), Range::new(10, 19),], 0);
439+ let selection = Selection::new(smallvec![Range::new(0, 8), Range::new(10, 19),], 0);
422− let result = split_on_matches(text.slice(..), &selections, &Regex::new(r"\s+").unwrap());
441+ let result = split_on_matches(text.slice(..), &selection, &Regex::new(r"\s+").unwrap());
424 assert_eq!(
443 assert_eq!(
425 result.ranges(),
444 result.ranges(),