From 905fbacbc7dd7c3b0b244dd85b678e6797f800ed Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Sat, 4 Jun 2022 15:01:43 -0700 Subject: [PATCH 1/2] vim: Avoid collapsing selections on editor creation when vim_mode is disabled --- crates/vim/src/vim.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/vim/src/vim.rs b/crates/vim/src/vim.rs index 89647b56e2..2f18d510d8 100644 --- a/crates/vim/src/vim.rs +++ b/crates/vim/src/vim.rs @@ -157,7 +157,7 @@ impl Vim { map.clip_point(selection.head(), Bias::Left), selection.goal, ); - if state.empty_selections_only() { + if self.enabled && state.empty_selections_only() { selection.collapse_to(selection.head(), selection.goal) } }); From 492cc716d3eeed6aebb894f63e7a1449acb9f63e Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Mon, 6 Jun 2022 08:14:49 +0200 Subject: [PATCH 2/2] Don't manipulate selections when syncing options if vim-mode is disabled Previously, we were always mutating selections when `sync_editor_options` was called. This seems to happen every time vim is enabled/disabled, but also when vim is disabled and editors are simply focused/blurred. This commit changes it so that we only manipulate selections when vim-mode is active. --- crates/vim/src/vim.rs | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/crates/vim/src/vim.rs b/crates/vim/src/vim.rs index 2f18d510d8..544dbf174f 100644 --- a/crates/vim/src/vim.rs +++ b/crates/vim/src/vim.rs @@ -143,6 +143,17 @@ impl Vim { matches!(state.mode, Mode::Visual { line: true }); let context_layer = state.keymap_context_layer(); editor.set_keymap_context_layer::(context_layer); + editor.change_selections(None, cx, |s| { + s.move_with(|map, selection| { + selection.set_head( + map.clip_point(selection.head(), Bias::Left), + selection.goal, + ); + if state.empty_selections_only() { + selection.collapse_to(selection.head(), selection.goal) + } + }); + }) } else { editor.set_cursor_shape(CursorShape::Bar, cx); editor.set_clip_at_line_ends(false, cx); @@ -150,18 +161,6 @@ impl Vim { editor.selections.line_mode = false; editor.remove_keymap_context_layer::(); } - - editor.change_selections(None, cx, |s| { - s.move_with(|map, selection| { - selection.set_head( - map.clip_point(selection.head(), Bias::Left), - selection.goal, - ); - if self.enabled && state.empty_selections_only() { - selection.collapse_to(selection.head(), selection.goal) - } - }); - }) }); } } @@ -191,6 +190,14 @@ mod test { cx.simulate_keystrokes(["h", "j", "k", "l"]); cx.assert_editor_state("hjkl|"); + // Selections aren't changed if editor is blurred but vim-mode is still disabled. + cx.set_state("[hjkl}", Mode::Normal); + cx.assert_editor_state("[hjkl}"); + cx.update_editor(|_, cx| cx.blur()); + cx.assert_editor_state("[hjkl}"); + cx.update_editor(|_, cx| cx.focus_self()); + cx.assert_editor_state("[hjkl}"); + // Enabling dynamically sets vim mode again and restores normal mode cx.enable_vim(); assert_eq!(cx.mode(), Mode::Normal);