diff --git a/assets/keymaps/default.json b/assets/keymaps/default.json index a8b9076633..a1dbf98fbe 100644 --- a/assets/keymaps/default.json +++ b/assets/keymaps/default.json @@ -138,10 +138,7 @@ { "context": "Editor && mode == auto_height", "bindings": { - "alt-enter": [ - "editor::Input", - "\n" - ] + "alt-enter": "editor::Newline" } }, { diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 7118f3c0ff..1bda73e74e 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -98,9 +98,6 @@ pub struct Jump { anchor: language::Anchor, } -#[derive(Clone, Deserialize, PartialEq)] -pub struct Input(pub String); - #[derive(Clone, Deserialize, PartialEq)] pub struct SelectToBeginningOfLine { #[serde(default)] @@ -214,7 +211,6 @@ actions!( impl_actions!( editor, [ - Input, SelectNext, SelectToBeginningOfLine, SelectToEndOfLine, @@ -5772,6 +5768,7 @@ pub enum Event { SelectionsChanged { local: bool }, ScrollPositionChanged { local: bool }, Closed, + IgnoredInput, } pub struct EditorFocused(pub ViewHandle); @@ -5916,6 +5913,11 @@ impl View for Editor { text: &str, cx: &mut ViewContext, ) { + if !self.input_enabled { + cx.emit(Event::IgnoredInput); + return; + } + self.transact(cx, |this, cx| { if let Some(range) = range_utf16.or_else(|| this.marked_text_range(cx)) { this.change_selections(None, cx, |selections| { @@ -5934,6 +5936,11 @@ impl View for Editor { new_selected_range_utf16: Option>, cx: &mut ViewContext, ) { + if !self.input_enabled { + cx.emit(Event::IgnoredInput); + return; + } + self.transact(cx, |this, cx| { let range_to_replace = if let Some(mut marked_range) = this.marked_text_range(cx) { if let Some(relative_range_utf16) = range_utf16.as_ref() { diff --git a/crates/file_finder/src/file_finder.rs b/crates/file_finder/src/file_finder.rs index 720e0142be..5603fa22ef 100644 --- a/crates/file_finder/src/file_finder.rs +++ b/crates/file_finder/src/file_finder.rs @@ -279,7 +279,7 @@ impl PickerDelegate for FileFinder { #[cfg(test)] mod tests { use super::*; - use editor::{Editor, Input}; + use editor::Editor; use menu::{Confirm, SelectNext}; use serde_json::json; use workspace::{AppState, Workspace}; @@ -326,12 +326,14 @@ mod tests { .downcast::() .unwrap() }); - cx.dispatch_action(window_id, Input("b".into())); - cx.dispatch_action(window_id, Input("n".into())); - cx.dispatch_action(window_id, Input("a".into())); finder - .condition(&cx, |finder, _| finder.matches.len() == 2) + .update(cx, |finder, cx| { + finder.update_matches("bna".to_string(), cx) + }) .await; + finder.read_with(cx, |finder, _| { + assert_eq!(finder.matches.len(), 2); + }); let active_pane = cx.read(|cx| workspace.read(cx).active_pane().clone()); cx.dispatch_action(window_id, SelectNext); diff --git a/crates/vim/src/editor_events.rs b/crates/vim/src/editor_events.rs index c68e5182b0..055b0bdb08 100644 --- a/crates/vim/src/editor_events.rs +++ b/crates/vim/src/editor_events.rs @@ -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::(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::(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); + } + }); + } + _ => (), } } })); diff --git a/crates/vim/src/vim.rs b/crates/vim/src/vim.rs index 5655e51e29..445d25a91c 100644 --- a/crates/vim/src/vim.rs +++ b/crates/vim/src/vim.rs @@ -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