fix jumplist

This commit is contained in:
Yara 2026-04-24 15:15:14 +02:00
parent 4a5fbf6a3f
commit 0c7b014d33
6 changed files with 201 additions and 0 deletions

View file

@ -2286,6 +2286,64 @@ mod test {
cx.shared_state().await.assert_matches();
}
#[gpui::test]
async fn test_jump_list_regular_motions(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx).await;
cx.set_shared_state(indoc! {"
ˇ
fn a() { }
fn b() { }
fn b() { }"})
.await;
cx.simulate_and_assert_matches(["gg", "20j", "ctrl-o"])
.await;
}
#[gpui::test]
async fn test_jump_list_regular_motions_between_jumps(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx).await;
cx.set_shared_state(indoc! {"
ˇfn a() { }
fn b() { }
fn b() { }"})
.await;
cx.simulate_and_assert_matches(["3 }", "2l", "ctrl-o", "4d", "ctrl-i"])
.await;
}
#[gpui::test]
async fn test_undo_last_line(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx).await;

View file

@ -268,6 +268,15 @@ impl NeovimBackedTestContext {
self.simulate_keystrokes(keystroke_texts);
}
/// Run multiple sequences of keystrokes, asserting that both states remain
/// in-sync between every sequence.
pub async fn simulate_and_assert_matches(&mut self, sequences: impl IntoIterator<Item = &str>) {
for sequence in sequences {
self.simulate_shared_keystrokes(sequence).await;
self.shared_state().await.assert_matches();
}
}
#[must_use]
pub async fn simulate(&mut self, keystrokes: &str, initial_state: &str) -> SharedState {
self.set_shared_state(initial_state).await;

View file

@ -0,0 +1,7 @@
{"Put":{"state":"ˇ\nfn a() { }\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nfn b() { }\n\nfn b() { }"}}
{"Key":"gg"}
{"Get":{"state":"ˇ\nfn a() { }\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nfn b() { }\n\nfn b() { }","mode":"Normal"}}
{"Key":"20j"}
{"Get":{"state":"ˇ\nfn a() { }\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nfn b() { }\n\nfn b() { }","mode":"Normal"}}
{"Key":"ctrl-o"}
{"Get":{"state":"ˇ\nfn a() { }\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nfn b() { }\n\nfn b() { }","mode":"Normal"}}

View file

@ -0,0 +1,12 @@
{"Put":{"state":"ˇfn a() { }\n\nfn b() { }\n\nfn b() { }"}}
{"Key":"3"}
{"Key":"}"}
{"Get":{"state":"fn a() { }\n\nfn b() { }\n\nfn b() { ˇ}","mode":"Normal"}}
{"Key":"2l"}
{"Get":{"state":"fn a() { }\n\nfn b() { }\n\nfn b() { ˇ}","mode":"Normal"}}
{"Key":"ctrl-o"}
{"Get":{"state":"ˇfn a() { }\n\nfn b() { }\n\nfn b() { }","mode":"Normal"}}
{"Key":"4d"}
{"Get":{"state":"ˇfn a() { }\n\nfn b() { }\n\nfn b() { }","mode":"Normal"}}
{"Key":"ctrl-i"}
{"Get":{"state":"fn a() { }\n\nfn b() { }\n\nfn b() { ˇ}","mode":"Normal"}}

115
crates/vim/test_output.txt Normal file
View file

@ -0,0 +1,115 @@
running 3 tests
test normal::test::test_jump_list_regular_motions ... FAILED
test normal::test::test_jump_list_regular_motions_between_jumps ... ok
test normal::test::test_jump_list ... ok
failures:
---- normal::test::test_jump_list_regular_motions stdout ----
thread 'normal::test::test_jump_list_regular_motions' (356219) panicked at crates/vim/src/test/neovim_backed_test_context.rs:276:39:
Test failed (zed does not match nvim behavior)
# initial state:
ˇ
fn a() { }
fn b() { }
fn b() { }
# keystrokes:
gg 20j ctrl-o
# neovim (NORMAL):
ˇ
fn a() { }
fn b() { }
fn b() { }
# zed (NORMAL):
fn a() { }
fn b() { }
fn b() { }ˇ
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
normal::test::test_jump_list_regular_motions
test result: FAILED. 2 passed; 1 failed; 0 ignored; 0 measured; 496 filtered out; finished in 0.50s

0
test_output.txt Normal file
View file