2023-04-20 21:25:11 +00:00
|
|
|
use crate::Vim;
|
|
|
|
use editor::{EditorBlurred, EditorFocused, EditorReleased};
|
|
|
|
use gpui::AppContext;
|
2022-03-25 02:24:36 +00:00
|
|
|
|
2023-04-06 21:49:03 +00:00
|
|
|
pub fn init(cx: &mut AppContext) {
|
2023-02-08 23:01:42 +00:00
|
|
|
cx.subscribe_global(focused).detach();
|
|
|
|
cx.subscribe_global(blurred).detach();
|
|
|
|
cx.subscribe_global(released).detach();
|
2022-03-25 02:24:36 +00:00
|
|
|
}
|
|
|
|
|
2023-04-06 21:49:03 +00:00
|
|
|
fn focused(EditorFocused(editor): &EditorFocused, cx: &mut AppContext) {
|
2023-04-27 17:43:09 +00:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-04-20 15:29:14 +00:00
|
|
|
cx.update_window(editor.window_id(), |cx| {
|
|
|
|
Vim::update(cx, |vim, cx| {
|
2023-04-20 21:25:11 +00:00
|
|
|
vim.set_active_editor(editor.clone(), cx);
|
2023-04-20 15:29:14 +00:00
|
|
|
});
|
2022-03-25 02:24:36 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-04-06 21:49:03 +00:00
|
|
|
fn blurred(EditorBlurred(editor): &EditorBlurred, cx: &mut AppContext) {
|
2023-04-20 15:29:14 +00:00
|
|
|
cx.update_window(editor.window_id(), |cx| {
|
|
|
|
Vim::update(cx, |vim, cx| {
|
|
|
|
if let Some(previous_editor) = vim.active_editor.clone() {
|
|
|
|
if previous_editor == editor.clone() {
|
|
|
|
vim.active_editor = None;
|
|
|
|
}
|
2022-03-25 02:24:36 +00:00
|
|
|
}
|
2023-04-17 09:17:35 +00:00
|
|
|
|
2023-05-04 14:18:01 +00:00
|
|
|
editor.update(cx, |editor, cx| Vim::unhook_vim_settings(editor, cx))
|
2023-04-17 09:17:35 +00:00
|
|
|
});
|
2023-04-20 15:29:14 +00:00
|
|
|
});
|
2022-03-25 02:24:36 +00:00
|
|
|
}
|
|
|
|
|
2023-04-06 21:49:03 +00:00
|
|
|
fn released(EditorReleased(editor): &EditorReleased, cx: &mut AppContext) {
|
2023-04-20 15:29:14 +00:00
|
|
|
cx.update_window(editor.window_id(), |cx| {
|
|
|
|
cx.update_default_global(|vim: &mut Vim, _| {
|
|
|
|
if let Some(previous_editor) = vim.active_editor.clone() {
|
|
|
|
if previous_editor == editor.clone() {
|
|
|
|
vim.active_editor = None;
|
|
|
|
}
|
2022-03-25 02:24:36 +00:00
|
|
|
}
|
2023-04-20 15:29:14 +00:00
|
|
|
});
|
2022-03-25 02:24:36 +00:00
|
|
|
});
|
|
|
|
}
|