toggling of block comments (#4718)

This commit is contained in:
Gabriel Dinner-David 2024-02-27 08:36:25 -05:00 committed by GitHub
parent f46a09ab4f
commit 26b3dc29be
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 568 additions and 29 deletions

View file

@ -14,6 +14,8 @@ pub trait RopeSliceExt<'a>: Sized {
byte_range: R,
) -> RegexInput<RopeyCursor<'a>>;
fn regex_input_at<R: RangeBounds<usize>>(self, char_range: R) -> RegexInput<RopeyCursor<'a>>;
fn first_non_whitespace_char(self) -> Option<usize>;
fn last_non_whitespace_char(self) -> Option<usize>;
}
impl<'a> RopeSliceExt<'a> for RopeSlice<'a> {
@ -64,4 +66,13 @@ impl<'a> RopeSliceExt<'a> for RopeSlice<'a> {
};
input.range(byte_range)
}
fn first_non_whitespace_char(self) -> Option<usize> {
self.chars().position(|ch| !ch.is_whitespace())
}
fn last_non_whitespace_char(self) -> Option<usize> {
self.chars_at(self.len_chars())
.reversed()
.position(|ch| !ch.is_whitespace())
.map(|pos| self.len_chars() - pos - 1)
}
}