From df52fea84bd8bc62da7e754252d1d6f1f8c7ee10 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 3 May 2023 13:14:10 -0400 Subject: [PATCH 1/3] Explicitly re-process final character --- helix-term/src/ui/editor.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index fd8e8fb21b47..ba765960ebfd 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -853,7 +853,8 @@ impl EditorView { commands::insert::insert_char(cx, ch) } } - KeymapResult::Cancelled(pending) => { + KeymapResult::Cancelled(mut pending) => { + let last_evt = pending.pop().unwrap(); for ev in pending { match ev.char() { Some(ch) => commands::insert::insert_char(cx, ch), @@ -866,6 +867,14 @@ impl EditorView { } } } + match self.handle_keymap_event(Mode::Insert, cx, last_evt) { + Some(KeymapResult::NotFound) => { + if let Some(ch) = last_evt.char() { + commands::insert::insert_char(cx, ch) + } + } + _ => (), + } } _ => unreachable!(), } From 497b7f3af8bf514a2156f88b38318b1b3b0befbd Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 3 May 2023 22:05:30 -0400 Subject: [PATCH 2/3] Move changes to handle_keymap_event --- helix-term/src/ui/editor.rs | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index ba765960ebfd..1c00b436ba2d 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -830,17 +830,23 @@ impl EditorView { last_mode = current_mode; }; - match &key_result { + match key_result { KeymapResult::Matched(command) => { - execute_command(command); + execute_command(&command); } KeymapResult::Pending(node) => cxt.editor.autoinfo = Some(node.infobox()), KeymapResult::MatchedSequence(commands) => { for command in commands { - execute_command(command); + execute_command(&command); } } - KeymapResult::NotFound | KeymapResult::Cancelled(_) => return Some(key_result), + KeymapResult::NotFound => return Some(key_result), + KeymapResult::Cancelled(mut pending) => { + if !matches!(self.keymaps.get(mode, event), KeymapResult::NotFound) { + pending.pop(); + } + return Some(KeymapResult::Cancelled(pending)); + } } None } @@ -853,8 +859,7 @@ impl EditorView { commands::insert::insert_char(cx, ch) } } - KeymapResult::Cancelled(mut pending) => { - let last_evt = pending.pop().unwrap(); + KeymapResult::Cancelled(pending) => { for ev in pending { match ev.char() { Some(ch) => commands::insert::insert_char(cx, ch), @@ -867,14 +872,6 @@ impl EditorView { } } } - match self.handle_keymap_event(Mode::Insert, cx, last_evt) { - Some(KeymapResult::NotFound) => { - if let Some(ch) = last_evt.char() { - commands::insert::insert_char(cx, ch) - } - } - _ => (), - } } _ => unreachable!(), } From 9a421171220cb5944f3097bc72369e8fd5850e78 Mon Sep 17 00:00:00 2001 From: Sam Date: Sun, 7 May 2023 11:11:47 -0400 Subject: [PATCH 3/3] Make recursive call, add (nonworking) test cases --- helix-term/src/ui/editor.rs | 5 ++++- helix-term/tests/test/movement.rs | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 1c00b436ba2d..d8b21e086cf5 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -842,7 +842,10 @@ impl EditorView { } KeymapResult::NotFound => return Some(key_result), KeymapResult::Cancelled(mut pending) => { - if !matches!(self.keymaps.get(mode, event), KeymapResult::NotFound) { + if !matches!( + self.handle_keymap_event(mode, cxt, event), + Some(KeymapResult::NotFound) + ) { pending.pop(); } return Some(KeymapResult::Cancelled(pending)); diff --git a/helix-term/tests/test/movement.rs b/helix-term/tests/test/movement.rs index 9a48cdbcb9fb..46ae3c48efeb 100644 --- a/helix-term/tests/test/movement.rs +++ b/helix-term/tests/test/movement.rs @@ -410,6 +410,23 @@ async fn cursor_position_append_eof() -> anyhow::Result<()> { Ok(()) } +#[tokio::test(flavor = "multi_thread")] +async fn repeated_key_movement() -> anyhow::Result<()> { + test(( + "#[|f]#oo", + "]]", + helpers::platform_line("#[|f]#oo\n"), + )) + .await?; + test(( + "#[|f]#oo\n\nbar", + "]]p", + helpers::platform_line("#[foo\n|]#\nbar"), + )) + .await?; + Ok(()) +} + #[tokio::test(flavor = "multi_thread")] async fn select_mode_tree_sitter_next_function_is_union_of_objects() -> anyhow::Result<()> { test_with_config(