From 7dcddf98c6e0ae6b307c49cb26a7e67ca70f0ea0 Mon Sep 17 00:00:00 2001 From: CalebLarsen <43345286+CalebLarsen@users.noreply.github.com> Date: Tue, 27 May 2025 09:44:47 -0500 Subject: [PATCH] Append changes to history on jumps (#13619) Co-authored-by: Michael Davis --- helix-term/src/commands.rs | 3 +- helix-term/tests/test/commands/insert.rs | 37 ++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 10b7b1662..604d69243 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -3762,7 +3762,8 @@ fn normal_mode(cx: &mut Context) { } // Store a jump on the jumplist. -fn push_jump(view: &mut View, doc: &Document) { +fn push_jump(view: &mut View, doc: &mut Document) { + doc.append_changes_to_history(view); let jump = (doc.id(), doc.selection(view.id).clone()); view.jumps.push(jump); } diff --git a/helix-term/tests/test/commands/insert.rs b/helix-term/tests/test/commands/insert.rs index d83dda84b..edec192cc 100644 --- a/helix-term/tests/test/commands/insert.rs +++ b/helix-term/tests/test/commands/insert.rs @@ -534,3 +534,40 @@ async fn try_restore_indent() -> anyhow::Result<()> { Ok(()) } + +// Tests being able to jump in insert mode, then undo the write performed by the jump +// https://github.com/helix-editor/helix/issues/13480 +#[tokio::test(flavor = "multi_thread")] +async fn test_jump_undo_redo() -> anyhow::Result<()> { + use helix_core::hashmap; + use helix_term::keymap; + use helix_view::document::Mode; + + let mut config = Config::default(); + config.keys.insert( + Mode::Insert, + keymap!({"Insert Mode" + "C-i" => goto_file_start, + "C-o" => goto_file_end, + }), + ); + + // Undo + test_with_config( + AppBuilder::new().with_config(config.clone()), + ("#[|]#", "iworldHello, u", "#[w|]#orld"), + ) + .await?; + + // Redo + test_with_config( + AppBuilder::new().with_config(config), + ( + "#[|]#", + "iworldHello, uiU", + "Hello, #[w|]#orld", + ), + ) + .await?; + Ok(()) +}