From 77c6243aa851b8e0d7a6c3655771825370bd356a Mon Sep 17 00:00:00 2001 From: 0x2CA <2478557459@qq.com> Date: Thu, 29 Aug 2024 11:31:51 +0800 Subject: [PATCH] vim: Fix Smart Relative Line Number (#17052) when the focused_vim is deactivate, focused_vim should set none. fix the problem that opening the first buffer from EmptyPane will not toggle,The reason is the edge case where focused_vim is none when opening for the first time. Release Notes: - N/A --- crates/vim/src/vim.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/crates/vim/src/vim.rs b/crates/vim/src/vim.rs index ac8257b058..d7015440f4 100644 --- a/crates/vim/src/vim.rs +++ b/crates/vim/src/vim.rs @@ -309,7 +309,12 @@ impl Vim { editor.set_autoindent(true); editor.selections.line_mode = false; editor.unregister_addon::(); - editor.set_relative_line_number(None, cx) + editor.set_relative_line_number(None, cx); + if let Some(vim) = Vim::globals(cx).focused_vim() { + if vim.entity_id() == cx.view().entity_id() { + Vim::globals(cx).focused_vim = None; + } + } } /// Register an action on the editor. @@ -656,6 +661,11 @@ impl Vim { editor.set_relative_line_number(Some(is_relative), cx) }); } + } else { + self.update_editor(cx, |vim, editor, cx| { + let is_relative = vim.mode != Mode::Insert; + editor.set_relative_line_number(Some(is_relative), cx) + }); } } Vim::globals(cx).focused_vim = Some(cx.view().downgrade());