Remove Input action, detect ignored input in vim via an event

This commit is contained in:
Max Brunsfeld 2022-07-21 13:40:48 -07:00
parent beeaec8647
commit 2142fca673
5 changed files with 34 additions and 27 deletions

View file

@ -22,9 +22,20 @@ fn editor_focused(EditorFocused(editor): &EditorFocused, cx: &mut MutableAppCont
vim.active_editor = Some(editor.downgrade());
vim.selection_subscription = Some(cx.subscribe(editor, |editor, event, cx| {
if editor.read(cx).leader_replica_id().is_none() {
if let editor::Event::SelectionsChanged { local: true } = event {
let newest_empty = editor.read(cx).selections.newest::<usize>(cx).is_empty();
editor_local_selections_changed(newest_empty, cx);
match event {
editor::Event::SelectionsChanged { local: true } => {
let newest_empty =
editor.read(cx).selections.newest::<usize>(cx).is_empty();
editor_local_selections_changed(newest_empty, cx);
}
editor::Event::IgnoredInput => {
Vim::update(cx, |vim, cx| {
if vim.active_operator().is_some() {
vim.clear_operator(cx);
}
});
}
_ => (),
}
}
}));

View file

@ -11,7 +11,7 @@ mod visual;
use collections::HashMap;
use command_palette::CommandPaletteFilter;
use editor::{Bias, Cancel, CursorShape, Editor, Input};
use editor::{Bias, Cancel, CursorShape, Editor};
use gpui::{impl_actions, MutableAppContext, Subscription, ViewContext, WeakViewHandle};
use serde::Deserialize;
@ -45,16 +45,6 @@ pub fn init(cx: &mut MutableAppContext) {
);
// Editor Actions
cx.add_action(|_: &mut Editor, _: &Input, cx| {
// If we have an unbound input with an active operator, cancel that operator. Otherwise forward
// the input to the editor
if Vim::read(cx).active_operator().is_some() {
// Defer without updating editor
MutableAppContext::defer(cx, |cx| Vim::update(cx, |vim, cx| vim.clear_operator(cx)))
} else {
cx.propagate_action()
}
});
cx.add_action(|_: &mut Editor, _: &Cancel, cx| {
// If we are in a non normal mode or have an active operator, swap to normal mode
// Otherwise forward cancel on to the editor