From 30f20024c0a7e578d7030089977805fbc669aa24 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Thu, 27 Apr 2023 10:43:09 -0700 Subject: [PATCH] Fix vim mode crash when active editor changes in inactive window Co-authored-by: Antonio Scandurra --- crates/vim/src/editor_events.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/crates/vim/src/editor_events.rs b/crates/vim/src/editor_events.rs index fadfdd3b0f..4324bc6054 100644 --- a/crates/vim/src/editor_events.rs +++ b/crates/vim/src/editor_events.rs @@ -9,11 +9,18 @@ pub fn init(cx: &mut AppContext) { } fn focused(EditorFocused(editor): &EditorFocused, cx: &mut AppContext) { + if let Some(previously_active_editor) = Vim::read(cx).active_editor.clone() { + cx.update_window(previously_active_editor.window_id(), |cx| { + Vim::update(cx, |vim, cx| { + vim.update_active_editor(cx, |previously_active_editor, cx| { + Vim::unhook_vim_settings(previously_active_editor, cx); + }); + }); + }); + } + cx.update_window(editor.window_id(), |cx| { Vim::update(cx, |vim, cx| { - vim.update_active_editor(cx, |previously_active_editor, cx| { - Vim::unhook_vim_settings(previously_active_editor, cx); - }); vim.set_active_editor(editor.clone(), cx); }); });