aboutsummaryrefslogtreecommitdiff
path: root/helix-stdx/src
diff options
context:
space:
mode:
authorGabriel Dinner-David2024-02-27 13:36:25 +0000
committerGitHub2024-02-27 13:36:25 +0000
commit26b3dc29be886c5a2ed1a5caaaf09eb730829c3e (patch)
tree7235f7dc402daaa9b3f5260d9a3f8aa166592ec6 /helix-stdx/src
parentf46a09ab4f945273c7baf32e58438b501914fabb (diff)
toggling of block comments (#4718)
Diffstat (limited to 'helix-stdx/src')
-rw-r--r--helix-stdx/src/rope.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/helix-stdx/src/rope.rs b/helix-stdx/src/rope.rs
index 7b4edda4..7e2549f5 100644
--- a/helix-stdx/src/rope.rs
+++ b/helix-stdx/src/rope.rs
@@ -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)
+ }
}