diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 263ba2f1c8..d92bd04251 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -9917,7 +9917,7 @@ mod tests { one| two three"}); - cx.simulate_input("."); + cx.simulate_keystroke("."); handle_completion_request( &mut cx, indoc! {" @@ -9963,9 +9963,9 @@ mod tests { two| three| additional edit"}); - cx.simulate_input(" "); + cx.simulate_keystroke(" "); assert!(cx.editor(|e, _| e.context_menu.is_none())); - cx.simulate_input("s"); + cx.simulate_keystroke("s"); assert!(cx.editor(|e, _| e.context_menu.is_none())); cx.assert_editor_state(indoc! {" @@ -9986,7 +9986,7 @@ mod tests { cx.condition(|editor, _| editor.context_menu_visible()) .await; - cx.simulate_input("i"); + cx.simulate_keystroke("i"); handle_completion_request( &mut cx, @@ -10021,11 +10021,11 @@ mod tests { }) }); cx.set_state("editor|"); - cx.simulate_input("."); + cx.simulate_keystroke("."); assert!(cx.editor(|e, _| e.context_menu.is_none())); - cx.simulate_input("c"); - cx.simulate_input("l"); - cx.simulate_input("o"); + cx.simulate_keystroke("c"); + cx.simulate_keystroke("l"); + cx.simulate_keystroke("o"); cx.assert_editor_state("editor.clo|"); assert!(cx.editor(|e, _| e.context_menu.is_none())); cx.update_editor(|editor, cx| { diff --git a/crates/editor/src/test.rs b/crates/editor/src/test.rs index 86928e5b8c..18c13a4ba6 100644 --- a/crates/editor/src/test.rs +++ b/crates/editor/src/test.rs @@ -165,12 +165,6 @@ impl<'a> EditorTestContext<'a> { }) } - pub fn simulate_input(&mut self, input: &str) { - self.editor.update(self.cx, |editor, cx| { - editor.handle_input(input, cx); - }); - } - pub fn update_buffer(&mut self, update: F) -> T where F: FnOnce(&mut Buffer, &mut ModelContext) -> T, diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index f4968ed2bc..b06bb642a2 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -475,7 +475,7 @@ impl TestAppContext { } pub fn dispatch_keystroke(&mut self, window_id: usize, keystroke: Keystroke, is_held: bool) { - self.cx.borrow_mut().update(|cx| { + let handled = self.cx.borrow_mut().update(|cx| { let presenter = cx .presenters_and_platform_windows .get(&window_id) @@ -484,12 +484,29 @@ impl TestAppContext { .clone(); let dispatch_path = presenter.borrow().dispatch_path(cx.as_ref()); - if !cx.dispatch_keystroke(window_id, dispatch_path, &keystroke) { - presenter - .borrow_mut() - .dispatch_event(Event::KeyDown(KeyDownEvent { keystroke, is_held }), cx); + if cx.dispatch_keystroke(window_id, dispatch_path, &keystroke) { + return true; } + if presenter.borrow_mut().dispatch_event( + Event::KeyDown(KeyDownEvent { + keystroke: keystroke.clone(), + is_held, + }), + cx, + ) { + return true; + } + + false }); + + if !handled && !keystroke.cmd && !keystroke.ctrl { + WindowInputHandler { + app: self.cx.clone(), + window_id, + } + .replace_text_in_range(None, &keystroke.key) + } } pub fn add_model(&mut self, build_model: F) -> ModelHandle