diff options
author | Blaž Hrastnik | 2021-02-09 07:39:17 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2021-02-09 07:39:17 +0000 |
commit | de5170dcdae4b1bd54ff3e1f33995827534bdfde (patch) | |
tree | 7d9d6f8e314e245a4209777c0470441904b78753 /helix-term | |
parent | 5e73f83efa406a6989fff6077b90dd77a7328b36 (diff) |
Parse input counts: 10w, etc.
Diffstat (limited to 'helix-term')
-rw-r--r-- | helix-term/src/ui/editor.rs | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 79e6ed93..2892e2e5 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -9,7 +9,7 @@ use std::borrow::Cow; use crossterm::{ cursor, - event::{read, Event, EventStream, KeyCode, KeyEvent}, + event::{read, Event, EventStream, KeyCode, KeyEvent, KeyModifiers}, }; use tui::{ backend::CrosstermBackend, @@ -333,10 +333,27 @@ impl Component for EditorView { } } mode => { - if let Some(command) = self.keymap[&mode].get(&keys) { - command(&mut cxt); - - // TODO: simplistic ensure cursor in view for now + match keys.as_slice() { + &[KeyEvent { + code: KeyCode::Char(i @ '0'..='9'), + modifiers: KeyModifiers::NONE, + }] => { + let i = i.to_digit(10).unwrap() as usize; + cxt.editor.count = Some(cxt.editor.count.map_or(i, |c| c * 10 + i)); + } + _ => { + // set the count + cxt.count = cxt.editor.count.take().unwrap_or(1); + // TODO: edge case: 0j -> reset to 1 + // if this fails, count was Some(0) + // debug_assert!(cxt.count != 0); + + if let Some(command) = self.keymap[&mode].get(&keys) { + command(&mut cxt); + + // TODO: simplistic ensure cursor in view for now + } + } } } } |