From 757a691b5e848331b842b182d9da47b81585f14a Mon Sep 17 00:00:00 2001 From: passivestar <60579014+passivestar@users.noreply.github.com> Date: Wed, 14 Feb 2024 21:55:21 +0400 Subject: [PATCH] Fix `Ctrl+Tab` and `Ctrl+Shift+Tab` on macOS --- editor/editor_node.cpp | 4 ++-- platform/macos/display_server_macos.mm | 26 +++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 827e2c7bf680..e521f6fac59f 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -6767,8 +6767,8 @@ EditorNode::EditorNode() { warning->add_button(TTR("Copy Text"), true, "copy"); warning->connect("custom_action", callable_mp(this, &EditorNode::_copy_warning)); - ED_SHORTCUT("editor/next_tab", TTR("Next Scene Tab"), KeyModifierMask::CMD_OR_CTRL + Key::TAB); - ED_SHORTCUT("editor/prev_tab", TTR("Previous Scene Tab"), KeyModifierMask::CMD_OR_CTRL + KeyModifierMask::SHIFT + Key::TAB); + ED_SHORTCUT("editor/next_tab", TTR("Next Scene Tab"), KeyModifierMask::CTRL + Key::TAB); + ED_SHORTCUT("editor/prev_tab", TTR("Previous Scene Tab"), KeyModifierMask::CTRL + KeyModifierMask::SHIFT + Key::TAB); ED_SHORTCUT("editor/filter_files", TTR("Focus FileSystem Filter"), KeyModifierMask::CMD_OR_CTRL + KeyModifierMask::ALT + Key::P); command_palette = EditorCommandPalette::get_singleton(); diff --git a/platform/macos/display_server_macos.mm b/platform/macos/display_server_macos.mm index 344dc1a8f754..165b1e4fbf55 100644 --- a/platform/macos/display_server_macos.mm +++ b/platform/macos/display_server_macos.mm @@ -699,10 +699,12 @@ } void DisplayServerMacOS::send_event(NSEvent *p_event) { - // Special case handling of command-period, which is traditionally a special - // shortcut in macOS and doesn't arrive at our regular keyDown handler. + // Special case handling of shortcuts that don't arrive at the regular keyDown handler if ([p_event type] == NSEventTypeKeyDown) { - if ((([p_event modifierFlags] & NSEventModifierFlagDeviceIndependentFlagsMask) == NSEventModifierFlagCommand) && [p_event keyCode] == 0x2f) { + NSEventModifierFlags flags = [p_event modifierFlags] & NSEventModifierFlagDeviceIndependentFlagsMask; + + // Command-period + if ((flags == NSEventModifierFlagCommand) && [p_event keyCode] == 0x2f) { Ref k; k.instantiate(); @@ -715,6 +717,24 @@ k->set_echo([p_event isARepeat]); Input::get_singleton()->parse_input_event(k); + return; + } + + // Ctrl+Tab and Ctrl+Shift+Tab + if (((flags == NSEventModifierFlagControl) || (flags == (NSEventModifierFlagControl | NSEventModifierFlagShift))) && [p_event keyCode] == 0x30) { + Ref k; + k.instantiate(); + + get_key_modifier_state([p_event modifierFlags], k); + k->set_window_id(DisplayServerMacOS::INVALID_WINDOW_ID); + k->set_pressed(true); + k->set_keycode(Key::TAB); + k->set_physical_keycode(Key::TAB); + k->set_key_label(Key::TAB); + k->set_echo([p_event isARepeat]); + + Input::get_singleton()->parse_input_event(k); + return; } } }