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
This commit is contained in:
0x2CA 2024-08-29 11:31:51 +08:00 committed by GitHub
parent 65b934e6f1
commit 77c6243aa8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -309,7 +309,12 @@ impl Vim {
editor.set_autoindent(true);
editor.selections.line_mode = false;
editor.unregister_addon::<VimAddon>();
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());