Remove 2 suffix for vim, diagnostics, go_to_line, theme_selector, command_palette, file_finder
Co-authored-by: Mikayla <mikayla@zed.dev>
This commit is contained in:
parent
37e6533b28
commit
252694390a
185 changed files with 1933 additions and 29192 deletions
|
@ -1,65 +1,67 @@
|
|||
use crate::{Vim, VimEvent};
|
||||
use editor::{EditorBlurred, EditorFocused, EditorReleased};
|
||||
use gpui::AppContext;
|
||||
use crate::Vim;
|
||||
use editor::{Editor, EditorEvent};
|
||||
use gpui::{AppContext, Entity, EntityId, View, ViewContext, WindowContext};
|
||||
|
||||
pub fn init(cx: &mut AppContext) {
|
||||
cx.subscribe_global(focused).detach();
|
||||
cx.subscribe_global(blurred).detach();
|
||||
cx.subscribe_global(released).detach();
|
||||
cx.observe_new_views(|_, cx: &mut ViewContext<Editor>| {
|
||||
let editor = cx.view().clone();
|
||||
cx.subscribe(&editor, |_, editor, event: &EditorEvent, cx| match event {
|
||||
EditorEvent::Focused => cx.window_context().defer(|cx| focused(editor, cx)),
|
||||
EditorEvent::Blurred => cx.window_context().defer(|cx| blurred(editor, cx)),
|
||||
_ => {}
|
||||
})
|
||||
.detach();
|
||||
|
||||
let id = cx.view().entity_id();
|
||||
cx.on_release(move |_, _, cx| released(id, cx)).detach();
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
|
||||
fn focused(EditorFocused(editor): &EditorFocused, cx: &mut AppContext) {
|
||||
if let Some(previously_active_editor) = Vim::read(cx).active_editor.clone() {
|
||||
previously_active_editor.window().update(cx, |cx| {
|
||||
Vim::update(cx, |vim, cx| {
|
||||
vim.update_active_editor(cx, |previously_active_editor, cx| {
|
||||
vim.unhook_vim_settings(previously_active_editor, cx)
|
||||
});
|
||||
fn focused(editor: View<Editor>, cx: &mut WindowContext) {
|
||||
if Vim::read(cx).active_editor.clone().is_some() {
|
||||
Vim::update(cx, |vim, cx| {
|
||||
vim.update_active_editor(cx, |previously_active_editor, cx| {
|
||||
vim.unhook_vim_settings(previously_active_editor, cx)
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
editor.window().update(cx, |cx| {
|
||||
Vim::update(cx, |vim, cx| {
|
||||
vim.set_active_editor(editor.clone(), cx);
|
||||
if vim.enabled {
|
||||
cx.emit_global(VimEvent::ModeChanged {
|
||||
mode: vim.state().mode,
|
||||
});
|
||||
}
|
||||
});
|
||||
Vim::update(cx, |vim, cx| {
|
||||
vim.set_active_editor(editor.clone(), cx);
|
||||
});
|
||||
}
|
||||
|
||||
fn blurred(EditorBlurred(editor): &EditorBlurred, cx: &mut AppContext) {
|
||||
editor.window().update(cx, |cx| {
|
||||
Vim::update(cx, |vim, cx| {
|
||||
vim.workspace_state.recording = false;
|
||||
vim.workspace_state.recorded_actions.clear();
|
||||
if let Some(previous_editor) = vim.active_editor.clone() {
|
||||
if previous_editor == editor.clone() {
|
||||
vim.clear_operator(cx);
|
||||
vim.active_editor = None;
|
||||
vim.editor_subscription = None;
|
||||
}
|
||||
fn blurred(editor: View<Editor>, cx: &mut WindowContext) {
|
||||
Vim::update(cx, |vim, cx| {
|
||||
vim.workspace_state.recording = false;
|
||||
vim.workspace_state.recorded_actions.clear();
|
||||
if let Some(previous_editor) = vim.active_editor.clone() {
|
||||
if previous_editor
|
||||
.upgrade()
|
||||
.is_some_and(|previous| previous == editor.clone())
|
||||
{
|
||||
vim.clear_operator(cx);
|
||||
vim.active_editor = None;
|
||||
vim.editor_subscription = None;
|
||||
}
|
||||
}
|
||||
|
||||
editor.update(cx, |editor, cx| vim.unhook_vim_settings(editor, cx))
|
||||
});
|
||||
editor.update(cx, |editor, cx| vim.unhook_vim_settings(editor, cx))
|
||||
});
|
||||
}
|
||||
|
||||
fn released(EditorReleased(editor): &EditorReleased, cx: &mut AppContext) {
|
||||
editor.window().update(cx, |cx| {
|
||||
Vim::update(cx, |vim, _| {
|
||||
if let Some(previous_editor) = vim.active_editor.clone() {
|
||||
if previous_editor == editor.clone() {
|
||||
vim.active_editor = None;
|
||||
vim.editor_subscription = None;
|
||||
}
|
||||
}
|
||||
vim.editor_states.remove(&editor.id())
|
||||
});
|
||||
fn released(entity_id: EntityId, cx: &mut AppContext) {
|
||||
cx.update_global(|vim: &mut Vim, _| {
|
||||
if vim
|
||||
.active_editor
|
||||
.as_ref()
|
||||
.is_some_and(|previous| previous.entity_id() == entity_id)
|
||||
{
|
||||
vim.active_editor = None;
|
||||
vim.editor_subscription = None;
|
||||
}
|
||||
vim.editor_states.remove(&entity_id)
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -67,7 +69,7 @@ fn released(EditorReleased(editor): &EditorReleased, cx: &mut AppContext) {
|
|||
mod test {
|
||||
use crate::{test::VimTestContext, Vim};
|
||||
use editor::Editor;
|
||||
use gpui::View;
|
||||
use gpui::{Context, Entity};
|
||||
use language::Buffer;
|
||||
|
||||
// regression test for blur called with a different active editor
|
||||
|
@ -75,18 +77,28 @@ mod test {
|
|||
async fn test_blur_focus(cx: &mut gpui::TestAppContext) {
|
||||
let mut cx = VimTestContext::new(cx, true).await;
|
||||
|
||||
let buffer = cx.add_model(|_| Buffer::new(0, 0, "a = 1\nb = 2\n"));
|
||||
let buffer = cx.new_model(|_| Buffer::new(0, 0, "a = 1\nb = 2\n"));
|
||||
let window2 = cx.add_window(|cx| Editor::for_buffer(buffer, None, cx));
|
||||
let editor2 = cx.read(|cx| window2.root(cx)).unwrap();
|
||||
let editor2 = cx
|
||||
.update(|cx| {
|
||||
window2.update(cx, |_, cx| {
|
||||
cx.focus_self();
|
||||
cx.view().clone()
|
||||
})
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
cx.update(|cx| {
|
||||
let vim = Vim::read(cx);
|
||||
assert_eq!(vim.active_editor.unwrap().id(), editor2.id())
|
||||
assert_eq!(
|
||||
vim.active_editor.as_ref().unwrap().entity_id(),
|
||||
editor2.entity_id(),
|
||||
)
|
||||
});
|
||||
|
||||
// no panic when blurring an editor in a different window.
|
||||
cx.update_editor(|editor1, cx| {
|
||||
editor1.focus_out(cx.handle().into_any(), cx);
|
||||
editor1.handle_blur(cx);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue