From 6e4e19d8fc29910a8e5945f20915750b4816a1b5 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Mon, 23 Oct 2023 15:19:38 +0200 Subject: [PATCH 1/2] Fix infinite loop in select all --- crates/editor/src/editor.rs | 2 +- crates/vim/src/test.rs | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 82945fc00b..ef2c459aad 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -6542,7 +6542,7 @@ impl Editor { { if selections .iter() - .find(|selection| selection.equals(&offset_range)) + .find(|selection| selection.range().overlaps(&offset_range)) .is_none() { next_selected_range = Some(offset_range); diff --git a/crates/vim/src/test.rs b/crates/vim/src/test.rs index 4fb87e70a0..3b4e2fed60 100644 --- a/crates/vim/src/test.rs +++ b/crates/vim/src/test.rs @@ -734,3 +734,27 @@ async fn test_paragraphs_dont_wrap(cx: &mut gpui::TestAppContext) { two"}) .await; } + +#[gpui::test] +async fn test_select_all_issue_2170(cx: &mut gpui::TestAppContext) { + let mut cx = VimTestContext::new(cx, true).await; + + cx.set_state( + indoc! {" + defmodule Test do + def test(a, ˇ[_, _] = b), do: IO.puts('hi') + end + "}, + Mode::Normal, + ); + cx.simulate_keystrokes(["g", "a"]); + // TODO: this would be better if it selected the [ not the space. + cx.assert_state( + indoc! {" + defmodule« ˇ»Test« ˇ»do + « ˇ»def« ˇ»test(a,« ˇ»[_,« ˇ»_]« ˇ»=« ˇ»b),« ˇ»do:« ˇ»IO.puts('hi') + end + "}, + Mode::Visual, + ); +} From 0e035c1a95d4c53172f30d4458bb5f06e7e3b927 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Tue, 24 Oct 2023 09:31:39 +0200 Subject: [PATCH 2/2] Fix character selection --- crates/editor/src/movement.rs | 6 ++++-- crates/language/src/buffer.rs | 2 +- crates/vim/src/test.rs | 5 ++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/crates/editor/src/movement.rs b/crates/editor/src/movement.rs index 580faf1050..5b780095d6 100644 --- a/crates/editor/src/movement.rs +++ b/crates/editor/src/movement.rs @@ -707,7 +707,9 @@ mod tests { let (snapshot, display_points) = marked_display_snapshot(marked_text, cx); assert_eq!( surrounding_word(&snapshot, display_points[1]), - display_points[0]..display_points[2] + display_points[0]..display_points[2], + "{}", + marked_text.to_string() ); } @@ -717,7 +719,7 @@ mod tests { assert("loremˇ ˇ ˇipsum", cx); assert("lorem\nˇˇˇ\nipsum", cx); assert("lorem\nˇˇipsumˇ", cx); - assert("lorem,ˇˇ ˇipsum", cx); + assert("loremˇ,ˇˇ ipsum", cx); assert("ˇloremˇˇ, ipsum", cx); } diff --git a/crates/language/src/buffer.rs b/crates/language/src/buffer.rs index 063c7616a8..0194123bd2 100644 --- a/crates/language/src/buffer.rs +++ b/crates/language/src/buffer.rs @@ -373,8 +373,8 @@ pub(crate) struct DiagnosticEndpoint { #[derive(Copy, Clone, Eq, PartialEq, PartialOrd, Ord, Debug)] pub enum CharKind { - Punctuation, Whitespace, + Punctuation, Word, } diff --git a/crates/vim/src/test.rs b/crates/vim/src/test.rs index 3b4e2fed60..9a6976183b 100644 --- a/crates/vim/src/test.rs +++ b/crates/vim/src/test.rs @@ -748,11 +748,10 @@ async fn test_select_all_issue_2170(cx: &mut gpui::TestAppContext) { Mode::Normal, ); cx.simulate_keystrokes(["g", "a"]); - // TODO: this would be better if it selected the [ not the space. cx.assert_state( indoc! {" - defmodule« ˇ»Test« ˇ»do - « ˇ»def« ˇ»test(a,« ˇ»[_,« ˇ»_]« ˇ»=« ˇ»b),« ˇ»do:« ˇ»IO.puts('hi') + defmodule Test do + def test(a, «[ˇ»_, _] = b), do: IO.puts('hi') end "}, Mode::Visual,