Unnamed repository; edit this file 'description' to name the repository.
Append changes to history on jumps (#13619)
Co-authored-by: Michael Davis <[email protected]>
CalebLarsen 9 months ago
parent c9e7b0f · commit 7dcddf9
-rw-r--r--helix-term/src/commands.rs3
-rw-r--r--helix-term/tests/test/commands/insert.rs37
2 files changed, 39 insertions, 1 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 10b7b166..604d6924 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 d83dda84..edec192c 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()),
+ ("#[|]#", "iworld<C-i>Hello, <esc>u", "#[w|]#orld"),
+ )
+ .await?;
+
+ // Redo
+ test_with_config(
+ AppBuilder::new().with_config(config),
+ (
+ "#[|]#",
+ "iworld<C-i>Hello, <esc>ui<C-o><esc>U",
+ "Hello, #[w|]#orld",
+ ),
+ )
+ .await?;
+ Ok(())
+}