Skip to content

Commit 4e12f05

Browse files
Fix dismissing the IME viewer with escape (#21413)
Co-Authored-By: Richard Feldman <[email protected]> Closes #21392 Release Notes: - Fixed dismissing the macOS IME menu with escape when no marked text was present --------- Co-authored-by: Richard Feldman <[email protected]>
1 parent f795ce9 commit 4e12f05

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

crates/gpui/src/platform/mac/window.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ struct MacWindowState {
331331
traffic_light_position: Option<Point<Pixels>>,
332332
previous_modifiers_changed_event: Option<PlatformInput>,
333333
keystroke_for_do_command: Option<Keystroke>,
334+
do_command_handled: Option<bool>,
334335
external_files_dragged: bool,
335336
// Whether the next left-mouse click is also the focusing click.
336337
first_mouse: bool,
@@ -609,6 +610,7 @@ impl MacWindow {
609610
.and_then(|titlebar| titlebar.traffic_light_position),
610611
previous_modifiers_changed_event: None,
611612
keystroke_for_do_command: None,
613+
do_command_handled: None,
612614
external_files_dragged: false,
613615
first_mouse: false,
614616
fullscreen_restore_bounds: Bounds::default(),
@@ -1251,14 +1253,22 @@ extern "C" fn handle_key_event(this: &Object, native_event: id, key_equivalent:
12511253
// otherwise we only send to the input handler if we don't have a matching binding.
12521254
// The input handler may call `do_command_by_selector` if it doesn't know how to handle
12531255
// a key. If it does so, it will return YES so we won't send the key twice.
1254-
if is_composing || event.keystroke.key.is_empty() {
1255-
window_state.as_ref().lock().keystroke_for_do_command = Some(event.keystroke.clone());
1256+
if is_composing || event.keystroke.key_char.is_none() {
1257+
{
1258+
let mut lock = window_state.as_ref().lock();
1259+
lock.keystroke_for_do_command = Some(event.keystroke.clone());
1260+
lock.do_command_handled.take();
1261+
drop(lock);
1262+
}
1263+
12561264
let handled: BOOL = unsafe {
12571265
let input_context: id = msg_send![this, inputContext];
12581266
msg_send![input_context, handleEvent: native_event]
12591267
};
12601268
window_state.as_ref().lock().keystroke_for_do_command.take();
1261-
if handled == YES {
1269+
if let Some(handled) = window_state.as_ref().lock().do_command_handled.take() {
1270+
return handled as BOOL;
1271+
} else if handled == YES {
12621272
return YES;
12631273
}
12641274

@@ -1377,6 +1387,14 @@ extern "C" fn handle_view_event(this: &Object, _: Sel, native_event: id) {
13771387
};
13781388

13791389
match &event {
1390+
PlatformInput::MouseDown(_) => {
1391+
drop(lock);
1392+
unsafe {
1393+
let input_context: id = msg_send![this, inputContext];
1394+
msg_send![input_context, handleEvent: native_event]
1395+
}
1396+
lock = window_state.as_ref().lock();
1397+
}
13801398
PlatformInput::MouseMove(
13811399
event @ MouseMoveEvent {
13821400
pressed_button: Some(_),
@@ -1790,10 +1808,11 @@ extern "C" fn do_command_by_selector(this: &Object, _: Sel, _: Sel) {
17901808
drop(lock);
17911809

17921810
if let Some((keystroke, mut callback)) = keystroke.zip(event_callback.as_mut()) {
1793-
(callback)(PlatformInput::KeyDown(KeyDownEvent {
1811+
let handled = (callback)(PlatformInput::KeyDown(KeyDownEvent {
17941812
keystroke,
17951813
is_held: false,
17961814
}));
1815+
state.as_ref().lock().do_command_handled = Some(!handled.propagate);
17971816
}
17981817

17991818
state.as_ref().lock().event_callback = event_callback;

0 commit comments

Comments
 (0)