aboutsummaryrefslogtreecommitdiff
path: root/helix-core/src
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-02-24 08:29:28 +0000
committerBlaž Hrastnik2021-02-25 07:49:30 +0000
commit01907b349771106865853dc2ea90aaa0913a7297 (patch)
tree42b0cb2288912148d7b86ba3ac55dadb5952d260 /helix-core/src
parent5fa1ba6b1c0a3ac4f93112b94be8477dc4d06b46 (diff)
commands: Implement count for a few more commands.
Diffstat (limited to 'helix-core/src')
-rw-r--r--helix-core/src/state.rs102
1 files changed, 55 insertions, 47 deletions
diff --git a/helix-core/src/state.rs b/helix-core/src/state.rs
index 78c9deb0..90e75eb4 100644
--- a/helix-core/src/state.rs
+++ b/helix-core/src/state.rs
@@ -120,76 +120,84 @@ impl State {
}
}
- pub fn move_next_word_start(slice: RopeSlice, mut pos: usize) -> usize {
+ pub fn move_next_word_start(slice: RopeSlice, mut pos: usize, count: usize) -> usize {
// TODO: confirm it's fine without using graphemes, I think it should be
- let ch = slice.char(pos);
- let next = slice.char(pos.saturating_add(1));
- if categorize(ch) != categorize(next) {
- pos += 1;
- }
+ for _ in 0..count {
+ let ch = slice.char(pos);
+ let next = slice.char(pos.saturating_add(1));
+ if categorize(ch) != categorize(next) {
+ pos += 1;
+ }
- // refetch
- let ch = slice.char(pos);
+ // refetch
+ let ch = slice.char(pos);
- if is_word(ch) {
- skip_over_next(slice, &mut pos, is_word);
- } else if ch.is_ascii_punctuation() {
- skip_over_next(slice, &mut pos, |ch| ch.is_ascii_punctuation());
- }
+ if is_word(ch) {
+ skip_over_next(slice, &mut pos, is_word);
+ } else if ch.is_ascii_punctuation() {
+ skip_over_next(slice, &mut pos, |ch| ch.is_ascii_punctuation());
+ }
- // TODO: don't include newline?
- skip_over_next(slice, &mut pos, |ch| ch.is_ascii_whitespace());
+ // TODO: don't include newline?
+ skip_over_next(slice, &mut pos, |ch| ch.is_ascii_whitespace());
+ }
pos
}
- pub fn move_prev_word_start(slice: RopeSlice, mut pos: usize) -> usize {
+ pub fn move_prev_word_start(slice: RopeSlice, mut pos: usize, count: usize) -> usize {
// TODO: confirm it's fine without using graphemes, I think it should be
- let ch = slice.char(pos);
- let prev = slice.char(pos.saturating_sub(1)); // TODO: just return original pos if at start
+ for _ in 0..count {
+ let ch = slice.char(pos);
+ let prev = slice.char(pos.saturating_sub(1)); // TODO: just return original pos if at start
- if categorize(ch) != categorize(prev) {
- pos -= 1;
- }
+ if categorize(ch) != categorize(prev) {
+ pos -= 1;
+ }
- // TODO: skip while eol
+ // TODO: skip while eol
- // TODO: don't include newline?
- skip_over_prev(slice, &mut pos, |ch| ch.is_ascii_whitespace());
+ // TODO: don't include newline?
+ skip_over_prev(slice, &mut pos, |ch| ch.is_ascii_whitespace());
- // refetch
- let ch = slice.char(pos);
+ // refetch
+ let ch = slice.char(pos);
- if is_word(ch) {
- skip_over_prev(slice, &mut pos, is_word);
- } else if ch.is_ascii_punctuation() {
- skip_over_prev(slice, &mut pos, |ch| ch.is_ascii_punctuation());
+ if is_word(ch) {
+ skip_over_prev(slice, &mut pos, is_word);
+ } else if ch.is_ascii_punctuation() {
+ skip_over_prev(slice, &mut pos, |ch| ch.is_ascii_punctuation());
+ }
+ pos = pos.saturating_add(1)
}
- pos.saturating_add(1)
+ pos
}
- pub fn move_next_word_end(slice: RopeSlice, mut pos: usize, _count: usize) -> usize {
- // TODO: confirm it's fine without using graphemes, I think it should be
- let ch = slice.char(pos);
- let next = slice.char(pos.saturating_add(1));
- if categorize(ch) != categorize(next) {
- pos += 1;
- }
+ pub fn move_next_word_end(slice: RopeSlice, mut pos: usize, count: usize) -> usize {
+ for _ in 0..count {
+ // TODO: confirm it's fine without using graphemes, I think it should be
+ let ch = slice.char(pos);
+ let next = slice.char(pos.saturating_add(1));
+ if categorize(ch) != categorize(next) {
+ pos += 1;
+ }
- // TODO: don't include newline?
- skip_over_next(slice, &mut pos, |ch| ch.is_ascii_whitespace());
+ // TODO: don't include newline?
+ skip_over_next(slice, &mut pos, |ch| ch.is_ascii_whitespace());
- // refetch
- let ch = slice.char(pos);
+ // refetch
+ let ch = slice.char(pos);
- if is_word(ch) {
- skip_over_next(slice, &mut pos, is_word);
- } else if ch.is_ascii_punctuation() {
- skip_over_next(slice, &mut pos, |ch| ch.is_ascii_punctuation());
+ if is_word(ch) {
+ skip_over_next(slice, &mut pos, is_word);
+ } else if ch.is_ascii_punctuation() {
+ skip_over_next(slice, &mut pos, |ch| ch.is_ascii_punctuation());
+ }
+ pos = pos.saturating_sub(1)
}
- pos.saturating_sub(1)
+ pos
}
pub fn move_selection(