From de5170dcdae4b1bd54ff3e1f33995827534bdfde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Tue, 9 Feb 2021 16:39:17 +0900 Subject: [PATCH] Parse input counts: 10w, etc. --- TODO.md | 2 +- helix-term/src/ui/editor.rs | 27 ++++++++++++++++++++++----- helix-view/src/editor.rs | 2 ++ 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/TODO.md b/TODO.md index 69f65a1f4..6ff5aeb22 100644 --- a/TODO.md +++ b/TODO.md @@ -11,7 +11,7 @@ - [ ] selection mode - [x] % for whole doc selection - [x] vertical splits -- [ ] input counts (30j) +- [x] input counts (30j) - [ ] respect view fullscreen flag - [ ] retain horiz when moving vertically - [ ] update lsp on redo/undo diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 79e6ed93f..2892e2e56 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 + } + } } } } diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 6b5b285db..762b9e962 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -10,6 +10,7 @@ pub struct Editor { pub tree: Tree, // pub documents: Vec, pub should_close: bool, + pub count: Option, pub theme: Theme, // TODO: share one instance pub language_servers: helix_lsp::Registry, } @@ -25,6 +26,7 @@ impl Editor { Self { tree: Tree::new(area), should_close: false, + count: None, theme, language_servers, }