From 26b3dc29be886c5a2ed1a5caaaf09eb730829c3e Mon Sep 17 00:00:00 2001 From: Gabriel Dinner-David Date: Tue, 27 Feb 2024 08:36:25 -0500 Subject: toggling of block comments (#4718) --- helix-stdx/src/rope.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'helix-stdx/src') 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>; fn regex_input_at>(self, char_range: R) -> RegexInput>; + fn first_non_whitespace_char(self) -> Option; + fn last_non_whitespace_char(self) -> Option; } 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 { + self.chars().position(|ch| !ch.is_whitespace()) + } + fn last_non_whitespace_char(self) -> Option { + self.chars_at(self.len_chars()) + .reversed() + .position(|ch| !ch.is_whitespace()) + .map(|pos| self.len_chars() - pos - 1) + } } -- cgit v1.2.3-70-g09d2