@@ -20,6 +20,7 @@ use tui::{
2020
2121pub struct EditorView {
2222 keymap: Keymaps,
23+ on_next_key: Option<Box<dyn FnOnce(&mut commands::Context, KeyEvent)>>,
2324}
2425
2526const OFFSET: u16 = 7; // 1 diagnostic + 5 linenr + 1 gutter
@@ -28,6 +29,7 @@ impl EditorView {
2829 pub fn new() -> Self {
2930 Self {
3031 keymap: keymap::default(),
32+ on_next_key: None,
3133 }
3234 }
3335 pub fn render_view(
@@ -366,46 +368,55 @@ impl Component for EditorView {
366368 editor: &mut cx.editor,
367369 count: 1,
368370 callback: None,
371+ on_next_key_callback: None,
369372 };
370373
371− match mode {
372− Mode::Insert => {
373− if let Some(command) = self.keymap[&Mode::Insert].get(&event) {
374− command(&mut cxt);
375− } else if let KeyEvent {
376− code: KeyCode::Char(c),
377− ..
378− } = event
379− {
380− commands::insert::insert_char(&mut cxt, c);
381− }
382− }
383− mode => {
384− match event {
385− KeyEvent {
386− code: KeyCode::Char(i @ '0'..='9'),
387− modifiers: KeyModifiers::NONE,
388− } => {
389− let i = i.to_digit(10).unwrap() as usize;
390− cxt.editor.count = Some(cxt.editor.count.map_or(i, |c| c * 10 + i));
374+ if let Some(on_next_key) = self.on_next_key.take() {
375+ // if there's a command waiting input, do that first
376+ on_next_key(&mut cxt, event);
377+ } else {
378+ match mode {
379+ Mode::Insert => {
380+ if let Some(command) = self.keymap[&Mode::Insert].get(&event) {
381+ command(&mut cxt);
382+ } else if let KeyEvent {
383+ code: KeyCode::Char(c),
384+ ..
385+ } = event
386+ {
387+ commands::insert::insert_char(&mut cxt, c);
391388 }
392− _ => {
393− // set the count
394− cxt.count = cxt.editor.count.take().unwrap_or(1);
395− // TODO: edge case: 0j -> reset to 1
396− // if this fails, count was Some(0)
397− // debug_assert!(cxt.count != 0);
398−
399− if let Some(command) = self.keymap[&mode].get(&event) {
400− command(&mut cxt);
401−
402− // TODO: simplistic ensure cursor in view for now
389+ }
390+ mode => {
391+ match event {
392+ KeyEvent {
393+ code: KeyCode::Char(i @ '0'..='9'),
394+ modifiers: KeyModifiers::NONE,
395+ } => {
396+ let i = i.to_digit(10).unwrap() as usize;
397+ cxt.editor.count =
398+ Some(cxt.editor.count.map_or(i, |c| c * 10 + i));
399+ }
400+ _ => {
401+ // set the count
402+ cxt.count = cxt.editor.count.take().unwrap_or(1);
403+ // TODO: edge case: 0j -> reset to 1
404+ // if this fails, count was Some(0)
405+ // debug_assert!(cxt.count != 0);
406+
407+ if let Some(command) = self.keymap[&mode].get(&event) {
408+ command(&mut cxt);
409+
410+ // TODO: simplistic ensure cursor in view for now
411+ }
403412 }
404413 }
405414 }
406415 }
407416 }
408417
418+ self.on_next_key = cxt.on_next_key_callback.take();
419+
409420 // appease borrowck
410421 let callback = cxt.callback.take();
411422 drop(cxt);