on master help sign in
Parse input counts: 10w, etc.
commitde5170dcdae4b1bd54ff3e1f33995827534bdfde authorBlaž Hrastnik <blaz@mxxn.io> dateTue 9 Feb 2021, 16:39 (6 years ago) parent5e73f83
3 files changed+25−6
TODO.md+1−1 helix-term/src/ui/editor.rs+22−5 helix-view/src/editor.rs+2
TODO.md+1−1
@@ -11,7 +11,7 @@
1111- [ ] selection mode
1212- [x] % for whole doc selection
1313- [x] vertical splits
14−- [ ] input counts (30j)
14+- [x] input counts (30j)
1515- [ ] respect view fullscreen flag
1616- [ ] retain horiz when moving vertically
1717- [ ] update lsp on redo/undo
helix-term/src/ui/editor.rs+22−5
@@ -9,7 +9,7 @@ use std::borrow::Cow;
99
1010use crossterm::{
1111 cursor,
12− event::{read, Event, EventStream, KeyCode, KeyEvent},
12+ event::{read, Event, EventStream, KeyCode, KeyEvent, KeyModifiers},
1313};
1414use tui::{
1515 backend::CrosstermBackend,
@@ -333,10 +333,27 @@ impl Component for EditorView {
333333 }
334334 }
335335 mode => {
336− if let Some(command) = self.keymap[&mode].get(&keys) {
337− command(&mut cxt);
338−
339− // TODO: simplistic ensure cursor in view for now
336+ match keys.as_slice() {
337+ &[KeyEvent {
338+ code: KeyCode::Char(i @ '0'..='9'),
339+ modifiers: KeyModifiers::NONE,
340+ }] => {
341+ let i = i.to_digit(10).unwrap() as usize;
342+ cxt.editor.count = Some(cxt.editor.count.map_or(i, |c| c * 10 + i));
343+ }
344+ _ => {
345+ // set the count
346+ cxt.count = cxt.editor.count.take().unwrap_or(1);
347+ // TODO: edge case: 0j -> reset to 1
348+ // if this fails, count was Some(0)
349+ // debug_assert!(cxt.count != 0);
350+
351+ if let Some(command) = self.keymap[&mode].get(&keys) {
352+ command(&mut cxt);
353+
354+ // TODO: simplistic ensure cursor in view for now
355+ }
356+ }
340357 }
341358 }
342359 }
helix-view/src/editor.rs+2
@@ -10,6 +10,7 @@ pub struct Editor {
1010 pub tree: Tree,
1111 // pub documents: Vec<Document>,
1212 pub should_close: bool,
13+ pub count: Option<usize>,
1314 pub theme: Theme, // TODO: share one instance
1415 pub language_servers: helix_lsp::Registry,
1516}
@@ -25,6 +26,7 @@ impl Editor {
2526 Self {
2627 tree: Tree::new(area),
2728 should_close: false,
29+ count: None,
2830 theme,
2931 language_servers,
3032 }