Commit ca007766 authored by Jake Goldsborough's avatar Jake Goldsborough

adds the W command to go to next WORD. adds a find next word forward function

parent cacada51
...@@ -175,4 +175,24 @@ impl Editor { ...@@ -175,4 +175,24 @@ impl Editor {
None None
} }
/// Get next WORD forward
/// "A WORD consists of a sequence of non-blank characters, separated with
/// whitespace. An empty line is also considered to be a WORD."
pub fn _next_word_forward(&self, n: usize) -> Option<usize> {
let mut dn = 0;
let mut x = self.x();
for (i, ch) in self.buffers.current_buffer()[self.y()].chars().skip(x).enumerate() {
if ch.is_whitespace() {
dn += 1;
if dn == n {
x += i + 1;
return Some(x);
}
}
}
None
}
} }
...@@ -199,6 +199,14 @@ impl Editor { ...@@ -199,6 +199,14 @@ impl Editor {
mov = true; mov = true;
} }
} }
(Command(Normal), Char('W')) => {
let pos = self._next_word_forward(n);
if let Some(p) = pos {
let y = self.y();
self.goto((p, y));
mov = true;
}
}
(Command(Normal), Char(';')) => (Command(Normal), Char(';')) =>
self.cursor_mut().mode = Mode::Primitive(PrimitiveMode::Prompt), self.cursor_mut().mode = Mode::Primitive(PrimitiveMode::Prompt),
(Command(Normal), Char(' ')) => self.next_cursor(), (Command(Normal), Char(' ')) => self.next_cursor(),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment