Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'src/text/cursor.rs')
| -rw-r--r-- | src/text/cursor.rs | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/text/cursor.rs b/src/text/cursor.rs index 32b33a7..077a750 100644 --- a/src/text/cursor.rs +++ b/src/text/cursor.rs @@ -93,8 +93,11 @@ pub fn caster<T, U>(x: impl FnMut(T) -> U) -> impl FnMut(T) -> U { } pub macro ceach($cursor: expr, $f:expr $( => $q:tt)?) { for i in (0..$cursor.inner.len()) { - let c = *$cursor.inner.get(i).expect("aw dangit"); - caster::<Cursor, _>($f)(c) $($q)?; + if let Some(&c) = $cursor.inner.get(i) { + caster::<Cursor, _>($f)(c) $($q)?; + } else { + log::error!("for some reason the number of cursors has changed."); + } } $cursor.coalesce(); } @@ -506,4 +509,14 @@ impl Cursors { // ) -> Vec<std::ops::Range<usize>> { // panic!(); // } + + pub fn sels<'a>( + &self, + text: &'a Rope, + ) -> std::iter::FilterMap< + impl Iterator<Item = Cursor> + ExactSizeIterator, + impl FnMut(Cursor) -> Option<RopeSlice<'a>>, + > { + self.iter().filter_map(|x| Some(text.get_slice(x.sel?)?)) + } } |