summaryrefslogtreecommitdiff
path: root/helix-core/src/words.rs
diff options
context:
space:
mode:
authorIvan Tham2021-06-05 10:15:50 +0000
committerBlaž Hrastnik2021-06-06 12:30:18 +0000
commit40744ce8356cb9307f8cb9b2adf2c57b80b1ef9f (patch)
tree3fc2a99ecdeb9e027d7c093c660e8863622b46b2 /helix-core/src/words.rs
parentaa8a8baeeb06cd94ed6329c535483f30835ec426 (diff)
Add ctrl-w in insert mode
It seemed to panic when I pressed too many times, but that is from lsp side.
Diffstat (limited to 'helix-core/src/words.rs')
-rw-r--r--helix-core/src/words.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/helix-core/src/words.rs b/helix-core/src/words.rs
new file mode 100644
index 00000000..0099d56a
--- /dev/null
+++ b/helix-core/src/words.rs
@@ -0,0 +1,33 @@
+use crate::movement::{categorize, is_horiz_blank, is_word, skip_over_prev};
+use ropey::RopeSlice;
+
+#[must_use]
+pub fn nth_prev_word_boundary(slice: RopeSlice, mut char_idx: usize, count: usize) -> usize {
+ let mut with_end = false;
+
+ for _ in 0..count {
+ if char_idx == 0 {
+ break;
+ }
+
+ // return if not skip while?
+ skip_over_prev(slice, &mut char_idx, |ch| ch == '\n');
+
+ with_end = skip_over_prev(slice, &mut char_idx, is_horiz_blank);
+
+ // refetch
+ let ch = slice.char(char_idx);
+
+ if is_word(ch) {
+ with_end = skip_over_prev(slice, &mut char_idx, is_word);
+ } else if ch.is_ascii_punctuation() {
+ with_end = skip_over_prev(slice, &mut char_idx, |ch| ch.is_ascii_punctuation());
+ }
+ }
+
+ if with_end {
+ char_idx
+ } else {
+ char_idx + 1
+ }
+}