diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index ee61c6b926229e0b46ee64e6abf21561d8350ed9..589f7b4c5222430d8b623314a775dcdd669c3c9b 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -24,7 +24,7 @@ use gpui::{ json::{self, ToJson}, platform::CursorStyle, text_layout::{self, Line, RunStyle, TextLayoutCache}, - AppContext, Axis, Border, CursorRegion, Element, ElementBox, Event, EventContext, KeyDownEvent, + AppContext, Axis, Border, CursorRegion, Element, ElementBox, Event, EventContext, LayoutContext, ModifiersChangedEvent, MouseButton, MouseEvent, MouseMovedEvent, MutableAppContext, PaintContext, Quad, Scene, ScrollWheelEvent, SizeConstraint, ViewContext, WeakViewHandle, @@ -278,21 +278,6 @@ impl EditorElement { true } - fn key_down(&self, input: Option<&str>, cx: &mut EventContext) -> bool { - let view = self.view.upgrade(cx.app).unwrap(); - - if view.is_focused(cx.app) { - if let Some(input) = input { - cx.dispatch_action(Input(input.to_string())); - true - } else { - false - } - } else { - false - } - } - fn modifiers_changed(&self, cmd: bool, cx: &mut EventContext) -> bool { cx.dispatch_action(CmdChanged { cmd_down: cmd }); false diff --git a/crates/editor/src/test.rs b/crates/editor/src/test.rs index dd05a14bd67bbb4e82d1f33a9d1b95be663cc44b..df9b48e6481e6a5c1dea8846ee1aa10a41ba50f8 100644 --- a/crates/editor/src/test.rs +++ b/crates/editor/src/test.rs @@ -141,13 +141,7 @@ impl<'a> EditorTestContext<'a> { pub fn simulate_keystroke(&mut self, keystroke_text: &str) { let keystroke = Keystroke::parse(keystroke_text).unwrap(); - let input = if keystroke.modified() { - None - } else { - Some(keystroke.key.clone()) - }; - self.cx - .dispatch_keystroke(self.window_id, keystroke, input, false); + self.cx.dispatch_keystroke(self.window_id, keystroke, false); } pub fn simulate_keystrokes(&mut self, keystroke_texts: [&str; COUNT]) { diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index 15f5bad570b4ae8d6bc5312b2e8ff9c9a7077d4e..d7b091886bd29a8db27a7997440bc2fe0b2268f6 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -498,13 +498,7 @@ impl TestAppContext { self.cx.borrow_mut().dispatch_global_action(action); } - pub fn dispatch_keystroke( - &mut self, - window_id: usize, - keystroke: Keystroke, - input: Option, - is_held: bool, - ) { + pub fn dispatch_keystroke(&mut self, window_id: usize, keystroke: Keystroke, is_held: bool) { self.cx.borrow_mut().update(|cx| { let presenter = cx .presenters_and_platform_windows @@ -515,14 +509,9 @@ impl TestAppContext { 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, - input, - is_held, - }), - cx, - ); + presenter + .borrow_mut() + .dispatch_event(Event::KeyDown(KeyDownEvent { keystroke, is_held }), cx); } }); } diff --git a/crates/gpui/src/platform/event.rs b/crates/gpui/src/platform/event.rs index 90b5d21fc2f7e1f8ec9092c598ca4a4c58cde658..6815619d1cc277f0d584c937b6f78164fc55723e 100644 --- a/crates/gpui/src/platform/event.rs +++ b/crates/gpui/src/platform/event.rs @@ -3,14 +3,12 @@ use crate::{geometry::vector::Vector2F, keymap::Keystroke}; #[derive(Clone, Debug)] pub struct KeyDownEvent { pub keystroke: Keystroke, - pub input: Option, pub is_held: bool, } #[derive(Clone, Debug)] pub struct KeyUpEvent { pub keystroke: Keystroke, - pub input: Option, } #[derive(Clone, Debug)] diff --git a/crates/gpui/src/platform/mac/event.rs b/crates/gpui/src/platform/mac/event.rs index b6cc066b2e255a84cc08ca7d79f6bffc16ebc23e..3840ef2eeb35b5f55005fa17d2d953d36108fba9 100644 --- a/crates/gpui/src/platform/mac/event.rs +++ b/crates/gpui/src/platform/mac/event.rs @@ -83,10 +83,8 @@ impl Event { let alt = modifiers.contains(NSEventModifierFlags::NSAlternateKeyMask); let shift = modifiers.contains(NSEventModifierFlags::NSShiftKeyMask); let cmd = modifiers.contains(NSEventModifierFlags::NSCommandKeyMask); - let function = modifiers.contains(NSEventModifierFlags::NSFunctionKeyMask); - - let (unmodified_chars, input) = get_key_text(native_event, cmd, ctrl, function)?; + let unmodified_chars = get_key_text(native_event)?; Some(Self::KeyDown(KeyDownEvent { keystroke: Keystroke { ctrl, @@ -95,7 +93,6 @@ impl Event { cmd, key: unmodified_chars.into(), }, - input, is_held: native_event.isARepeat() == YES, })) } @@ -105,10 +102,7 @@ impl Event { let alt = modifiers.contains(NSEventModifierFlags::NSAlternateKeyMask); let shift = modifiers.contains(NSEventModifierFlags::NSShiftKeyMask); let cmd = modifiers.contains(NSEventModifierFlags::NSCommandKeyMask); - let function = modifiers.contains(NSEventModifierFlags::NSFunctionKeyMask); - - let (unmodified_chars, input) = get_key_text(native_event, cmd, ctrl, function)?; - + let unmodified_chars = get_key_text(native_event)?; Some(Self::KeyUp(KeyUpEvent { keystroke: Keystroke { ctrl, @@ -117,7 +111,6 @@ impl Event { cmd, key: unmodified_chars.into(), }, - input, })) } NSEventType::NSLeftMouseDown @@ -238,27 +231,18 @@ impl Event { } } -unsafe fn get_key_text( - native_event: id, - cmd: bool, - ctrl: bool, - function: bool, -) -> Option<(&'static str, Option)> { +unsafe fn get_key_text(native_event: id) -> Option<&'static str> { let unmodified_chars = CStr::from_ptr(native_event.charactersIgnoringModifiers().UTF8String() as *mut c_char) .to_str() .unwrap(); - let mut input = None; let first_char = unmodified_chars.chars().next()?; use cocoa::appkit::*; #[allow(non_upper_case_globals)] let unmodified_chars = match first_char as u16 { - SPACE_KEY => { - input = Some(" ".to_string()); - "space" - } + SPACE_KEY => "space", BACKSPACE_KEY => "backspace", ENTER_KEY | NUMPAD_ENTER_KEY => "enter", ESCAPE_KEY => "escape", @@ -284,19 +268,8 @@ unsafe fn get_key_text( NSF10FunctionKey => "f10", NSF11FunctionKey => "f11", NSF12FunctionKey => "f12", - - _ => { - if !cmd && !ctrl && !function { - input = Some( - CStr::from_ptr(native_event.characters().UTF8String() as *mut c_char) - .to_str() - .unwrap() - .into(), - ); - } - unmodified_chars - } + _ => unmodified_chars, }; - Some((unmodified_chars, input)) + Some(unmodified_chars) } diff --git a/crates/gpui/src/platform/mac/window.rs b/crates/gpui/src/platform/mac/window.rs index cc23193830172d7c6d065a65b88890b111a6013f..ec05d1c8c563c419b40ef36d9a6c09b81921f0fc 100644 --- a/crates/gpui/src/platform/mac/window.rs +++ b/crates/gpui/src/platform/mac/window.rs @@ -279,7 +279,7 @@ struct WindowState { scene_to_render: Option, renderer: Renderer, command_queue: metal::CommandQueue, - last_fresh_keydown: Option<(Keystroke, Option)>, + last_fresh_keydown: Option, layer: id, traffic_light_position: Option, previous_modifiers_changed_event: Option, @@ -699,7 +699,7 @@ extern "C" fn handle_key_equivalent(this: &Object, _: Sel, native_event: id) -> if let Some(event) = event { window_state_borrow.pending_keydown_event = match event { Event::KeyDown(event) => { - let keydown = (event.keystroke.clone(), event.input.clone()); + let keydown = event.keystroke.clone(); // Ignore events from held-down keys after some of the initially-pressed keys // were released. if event.is_held { @@ -812,21 +812,19 @@ extern "C" fn cancel_operation(this: &Object, _sel: Sel, _sender: id) { let window_state = unsafe { get_window_state(this) }; let mut window_state_borrow = window_state.as_ref().borrow_mut(); - let chars = ".".to_string(); let keystroke = Keystroke { cmd: true, ctrl: false, alt: false, shift: false, - key: chars.clone(), + key: ".".into(), }; let event = Event::KeyDown(KeyDownEvent { keystroke: keystroke.clone(), - input: Some(chars.clone()), is_held: false, }); - window_state_borrow.last_fresh_keydown = Some((keystroke, Some(chars))); + window_state_borrow.last_fresh_keydown = Some(keystroke); if let Some(mut callback) = window_state_borrow.event_callback.take() { drop(window_state_borrow); callback(event);