From 03d06412a381d273695769840b498b32ef631963 Mon Sep 17 00:00:00 2001 From: "gcp-cherry-pick-bot[bot]" <98988430+gcp-cherry-pick-bot[bot]@users.noreply.github.com> Date: Mon, 8 Apr 2024 12:01:44 -0600 Subject: [PATCH] Fix panic in visual line mode with folds (cherry-pick #10284) (#10290) Cherry-picked Fix panic in visual line mode with folds (#10284) Fixes: #10266 Release Notes: - Added/Fixed/Improved ... ([#](https://github.com/zed-industries/zed/issues/)). Optionally, include screenshots / media showcasing your addition that can be included in the release notes. **or** - N/A Co-authored-by: Conrad Irwin --- crates/editor/src/display_map.rs | 5 +++- crates/vim/src/test.rs | 28 +++++++++++++++------- crates/vim/test_data/test_folds_panic.json | 10 ++++++++ 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/crates/editor/src/display_map.rs b/crates/editor/src/display_map.rs index f27499185343b7617d99ee10fb62daff18af15ff..014c570238246b77d86598cae3411da21083af3f 100644 --- a/crates/editor/src/display_map.rs +++ b/crates/editor/src/display_map.rs @@ -433,7 +433,10 @@ impl DisplaySnapshot { } else if range.start.row == self.max_buffer_row() || (range.end.column > 0 && range.end.row == self.max_buffer_row()) { - Point::new(range.start.row - 1, self.line_len(range.start.row - 1)) + Point::new( + range.start.row - 1, + self.buffer_snapshot.line_len(range.start.row - 1), + ) } else { self.prev_line_boundary(range.start).0 }; diff --git a/crates/vim/src/test.rs b/crates/vim/src/test.rs index f8b32fee5a305fac35aee243935b89b5a96fd94a..d2b516b613a030450f37470cfb3f392e42659b27 100644 --- a/crates/vim/src/test.rs +++ b/crates/vim/src/test.rs @@ -634,6 +634,25 @@ async fn test_folds_panic(cx: &mut gpui::TestAppContext) { cx.simulate_shared_keystrokes(["g", "g"]).await; cx.simulate_shared_keystrokes(["5", "d", "j"]).await; cx.assert_shared_state(indoc! { "ˇ"}).await; + + cx.set_shared_state(indoc! { " + fn boop() { + ˇbarp() + bazp() + } + "}) + .await; + cx.simulate_shared_keystrokes(["shift-v", "j", "j", "z", "f"]) + .await; + cx.simulate_shared_keystrokes(["escape"]).await; + cx.simulate_shared_keystrokes(["shift-g", "shift-v"]).await; + cx.assert_shared_state(indoc! { " + fn boop() { + barp() + bazp() + } + ˇ"}) + .await; } #[gpui::test] @@ -1038,12 +1057,3 @@ async fn test_undo(cx: &mut gpui::TestAppContext) { 3"}) .await; } - -#[gpui::test] -async fn test_command_palette(cx: &mut gpui::TestAppContext) { - let mut cx = VimTestContext::new(cx, true).await; - cx.simulate_keystroke(":"); - cx.simulate_input("go to definition"); - assert!(cx.debug_bounds("KEY_BINDING-f12").is_none()); - assert!(cx.debug_bounds("KEY_BINDING-g d").is_some()); -} diff --git a/crates/vim/test_data/test_folds_panic.json b/crates/vim/test_data/test_folds_panic.json index 3e5e337dcbcb9d636dd62a0728742f38af0fae0b..a215765b047f97eedf3704da527f3ae2df5ac2c8 100644 --- a/crates/vim/test_data/test_folds_panic.json +++ b/crates/vim/test_data/test_folds_panic.json @@ -11,3 +11,13 @@ {"Key":"d"} {"Key":"j"} {"Get":{"state":"ˇ","mode":"Normal"}} +{"Put":{"state":"fn boop() {\n ˇbarp()\n bazp()\n}\n"}} +{"Key":"shift-v"} +{"Key":"j"} +{"Key":"j"} +{"Key":"z"} +{"Key":"f"} +{"Key":"escape"} +{"Key":"shift-g"} +{"Key":"shift-v"} +{"Get":{"state":"fn boop() {\n barp()\n bazp()\n}\nˇ","mode":"VisualLine"}}