@@ -136,15 +136,27 @@ class ControlsTab {
136136 toggleNativeCommandTabIfNeeded ( )
137137 }
138138
139- private static func toggleNativeCommandTabIfNeeded ( ) {
140- for atShortcut in shortcuts . values {
141- let shortcut = atShortcut . shortcut
142- if ( shortcut . carbonModifierFlags == cmdKey || shortcut . carbonModifierFlags == ( cmdKey | shiftKey ) ) && shortcut . carbonKeyCode == kVK_Tab {
143- setNativeCommandTabEnabled ( false )
144- return
139+ /// commandTab and commandKeyAboveTab are self-contained in the "nextWindowShortcut" shortcuts
140+ /// but the keys of commandShiftTab can be spread between holdShortcut and a local shortcut
141+ static func combinedModifiersMatch ( _ modifiers1 : UInt32 , _ modifiers2 : UInt32 ) -> Bool {
142+ return ( 0 ..< 5 ) . contains {
143+ if let holdShortcut = shortcuts [ Preferences . indexToName ( " holdShortcut " , $0 ) ] {
144+ return ( holdShortcut . shortcut . carbonModifierFlags | modifiers1 ) == ( holdShortcut . shortcut . carbonModifierFlags | modifiers2 )
145145 }
146+ return false
146147 }
147- setNativeCommandTabEnabled ( true )
148+ }
149+
150+ private static func toggleNativeCommandTabIfNeeded( ) {
151+ let nativeHotkeys : [ CGSSymbolicHotKey : ( Shortcut ) -> Bool ] = [
152+ . commandTab: { ( shortcut) in shortcut. carbonKeyCode == kVK_Tab && shortcut. carbonModifierFlags == cmdKey } ,
153+ . commandShiftTab: { ( shortcut) in shortcut. carbonKeyCode == kVK_Tab && combinedModifiersMatch ( shortcut. carbonModifierFlags, UInt32 ( cmdKey | shiftKey) ) } ,
154+ . commandKeyAboveTab: { ( shortcut) in shortcut. carbonModifierFlags == cmdKey && shortcut. carbonKeyCode == kVK_ANSI_Grave } ,
155+ ]
156+ let overlappingHotkeys = shortcuts. values. compactMap { ( atShortcut) in nativeHotkeys. first { $1 ( atShortcut. shortcut) } ? . key }
157+ let nonOverlappingHotkeys : [ CGSSymbolicHotKey ] = Array ( Set ( nativeHotkeys. keys) . symmetricDifference ( Set ( overlappingHotkeys) ) )
158+ setNativeCommandTabEnabled ( false , overlappingHotkeys)
159+ setNativeCommandTabEnabled ( true , nonOverlappingHotkeys)
148160 }
149161
150162 @objc static func shortcutChangedCallback( _ sender: NSControl ) {
0 commit comments