editor_events.rs

  1use crate::{Vim, VimEvent};
  2use editor::{EditorBlurred, EditorFocused, EditorReleased};
  3use gpui::AppContext;
  4
  5pub fn init(cx: &mut AppContext) {
  6    // todo!()
  7    // cx.subscribe_global(focused).detach();
  8    // cx.subscribe_global(blurred).detach();
  9    // cx.subscribe_global(released).detach();
 10}
 11
 12fn focused(EditorFocused(editor): &EditorFocused, cx: &mut AppContext) {
 13    todo!();
 14    // if let Some(previously_active_editor) = Vim::read(cx).active_editor.clone() {
 15    //     previously_active_editor.window_handle().update(cx, |cx| {
 16    //         Vim::update(cx, |vim, cx| {
 17    //             vim.update_active_editor(cx, |previously_active_editor, cx| {
 18    //                 vim.unhook_vim_settings(previously_active_editor, cx)
 19    //             });
 20    //         });
 21    //     });
 22    // }
 23
 24    // editor.window().update(cx, |cx| {
 25    //     Vim::update(cx, |vim, cx| {
 26    //         vim.set_active_editor(editor.clone(), cx);
 27    //         if vim.enabled {
 28    //             cx.emit_global(VimEvent::ModeChanged {
 29    //                 mode: vim.state().mode,
 30    //             });
 31    //         }
 32    //     });
 33    // });
 34}
 35
 36fn blurred(EditorBlurred(editor): &EditorBlurred, cx: &mut AppContext) {
 37    todo!();
 38    // editor.window().update(cx, |cx| {
 39    //     Vim::update(cx, |vim, cx| {
 40    //         vim.workspace_state.recording = false;
 41    //         vim.workspace_state.recorded_actions.clear();
 42    //         if let Some(previous_editor) = vim.active_editor.clone() {
 43    //             if previous_editor == editor.clone() {
 44    //                 vim.clear_operator(cx);
 45    //                 vim.active_editor = None;
 46    //                 vim.editor_subscription = None;
 47    //             }
 48    //         }
 49
 50    //         editor.update(cx, |editor, cx| vim.unhook_vim_settings(editor, cx))
 51    //     });
 52    // });
 53}
 54
 55fn released(EditorReleased(editor): &EditorReleased, cx: &mut AppContext) {
 56    todo!();
 57    // editor.window().update(cx, |cx| {
 58    //     Vim::update(cx, |vim, _| {
 59    //         if let Some(previous_editor) = vim.active_editor.clone() {
 60    //             if previous_editor == editor.clone() {
 61    //                 vim.active_editor = None;
 62    //                 vim.editor_subscription = None;
 63    //             }
 64    //         }
 65    //         vim.editor_states.remove(&editor.id())
 66    //     });
 67    // });
 68}
 69
 70// #[cfg(test)]
 71// mod test {
 72//     use crate::{test::VimTestContext, Vim};
 73//     use editor::Editor;
 74//     use gpui::{Context, Entity};
 75//     use language::Buffer;
 76
 77//     // regression test for blur called with a different active editor
 78//     #[gpui::test]
 79//     async fn test_blur_focus(cx: &mut gpui::TestAppContext) {
 80//         let mut cx = VimTestContext::new(cx, true).await;
 81
 82//         let buffer = cx.build_model(|_| Buffer::new(0, 0, "a = 1\nb = 2\n"));
 83//         let window2 = cx.add_window(|cx| Editor::for_buffer(buffer, None, cx));
 84//         let editor2 = cx
 85//             .update(|cx| window2.update(cx, |editor, cx| cx.view()))
 86//             .unwrap();
 87
 88//         cx.update(|cx| {
 89//             let vim = Vim::read(cx);
 90//             assert_eq!(
 91//                 vim.active_editor.unwrap().entity_id().unwrap(),
 92//                 editor2.entity_id()
 93//             )
 94//         });
 95
 96//         // no panic when blurring an editor in a different window.
 97//         cx.update_editor(|editor1, cx| {
 98//             editor1.focus_out(cx.handle().into_any(), cx);
 99//         });
100//     }
101// }