From 42cd2ae1426b26f6821b9a47a18151d0159f8b68 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Thu, 26 May 2022 12:47:16 -0700 Subject: [PATCH] Avoid switching to visual mode when following in vim mode Co-authored-by: Keith Simmons --- crates/editor/src/editor.rs | 4 ++++ crates/vim/src/editor_events.rs | 10 ++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index b7ffe9ebbfb759a2f3e844741665a087e263fd49..b07ca1df2e588dc4b951c78f810c720baa66abdb 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -1025,6 +1025,10 @@ impl Editor { self.buffer.read(cx).replica_id() } + pub fn leader_replica_id(&self) -> Option { + self.leader_replica_id + } + pub fn buffer(&self) -> &ModelHandle { &self.buffer } diff --git a/crates/vim/src/editor_events.rs b/crates/vim/src/editor_events.rs index 092d369058270e8e12a1b3da03630cdc7cf8495f..8837f264d35eb40233685dfbf30ac5189359b618 100644 --- a/crates/vim/src/editor_events.rs +++ b/crates/vim/src/editor_events.rs @@ -21,9 +21,11 @@ fn editor_focused(EditorFocused(editor): &EditorFocused, cx: &mut MutableAppCont Vim::update(cx, |vim, cx| { vim.active_editor = Some(editor.downgrade()); vim.selection_subscription = Some(cx.subscribe(editor, |editor, event, cx| { - if let editor::Event::SelectionsChanged { local: true } = event { - let newest_empty = editor.read(cx).selections.newest::(cx).is_empty(); - editor_local_selections_changed(newest_empty, cx); + if editor.read(cx).leader_replica_id().is_none() { + if let editor::Event::SelectionsChanged { local: true } = event { + let newest_empty = editor.read(cx).selections.newest::(cx).is_empty(); + editor_local_selections_changed(newest_empty, cx); + } } })); @@ -57,7 +59,7 @@ fn editor_released(EditorReleased(editor): &EditorReleased, cx: &mut MutableAppC fn editor_local_selections_changed(newest_empty: bool, cx: &mut MutableAppContext) { Vim::update(cx, |vim, cx| { - if vim.state.mode == Mode::Normal && !newest_empty { + if vim.enabled && vim.state.mode == Mode::Normal && !newest_empty { vim.switch_mode(Mode::Visual { line: false }, cx) } })