fix: [after release: do nothing] was broken in v7.6.0 (closes #3929)
This commit is contained in:
1 parent
db305db392
commit
83b5319433
3 files changed
+44
-1
No files matched your search
@@ -83,7 +83,7 @@ class ATShortcut {
|
||||
// Another issue is events being dropped by macOS, which we never receive
|
||||
// Knowing this, we handle these edge-cases by double checking if holdShortcut is UP, when any shortcut state is UP
|
||||
// If it is, then we trigger the holdShortcut action
|
||||
if App.app.appIsBeingUsed {
|
||||
if App.app.appIsBeingUsed && Preferences.shortcutStyle[App.app.shortcutIndex] == .focusOnRelease {
|
||||
if let currentHoldShortcut = ControlsTab.shortcuts[Preferences.indexToName("holdShortcut", App.app.shortcutIndex)],
|
||||
id == currentHoldShortcut.id {
|
||||
let currentModifiers = cocoaToCarbonFlags(ModifierFlags.current)
|
||||
|
||||
@@ -111,9 +111,46 @@ final class KeyboardEventsUtilsTests: XCTestCase {
|
||||
XCTAssertEqual(ControlsTab.shortcutsActionsTriggered, ["nextWindowShortcut", "closeWindowShortcut", "holdShortcut"])
|
||||
}
|
||||
|
||||
func testOnReleaseDoNothing() throws {
|
||||
resetState()
|
||||
Preferences.shortcutStyle[0] = .doNothingOnRelease
|
||||
ModifierFlags.current = [.option]
|
||||
handleKeyboardEvent(nil, nil, nil, [.option], false)
|
||||
XCTAssertEqual(ControlsTab.shortcutsActionsTriggered, [])
|
||||
handleKeyboardEvent(KeyboardEventsTestable.globalShortcutsIds["nextWindowShortcut"], .down, nil, nil, false)
|
||||
XCTAssertEqual(ControlsTab.shortcutsActionsTriggered, ["nextWindowShortcut"])
|
||||
handleKeyboardEvent(KeyboardEventsTestable.globalShortcutsIds["nextWindowShortcut"], .up, nil, nil, false)
|
||||
XCTAssertEqual(ControlsTab.shortcutsActionsTriggered, ["nextWindowShortcut"])
|
||||
ModifierFlags.current = []
|
||||
handleKeyboardEvent(nil, nil, nil, [], false)
|
||||
XCTAssertEqual(ControlsTab.shortcutsActionsTriggered, ["nextWindowShortcut"])
|
||||
}
|
||||
|
||||
// alt-down > tab-down > tab-up > `-down > `-up
|
||||
func testTransitionFromOneShortcutToAnother() throws {
|
||||
resetState()
|
||||
ModifierFlags.current = [.option]
|
||||
handleKeyboardEvent(nil, nil, nil, [.option], false)
|
||||
XCTAssertEqual(ControlsTab.shortcutsActionsTriggered, [])
|
||||
handleKeyboardEvent(KeyboardEventsTestable.globalShortcutsIds["nextWindowShortcut"], .down, nil, nil, false)
|
||||
XCTAssertEqual(ControlsTab.shortcutsActionsTriggered, ["nextWindowShortcut"])
|
||||
handleKeyboardEvent(KeyboardEventsTestable.globalShortcutsIds["nextWindowShortcut"], .up, nil, nil, false)
|
||||
XCTAssertEqual(ControlsTab.shortcutsActionsTriggered, ["nextWindowShortcut"])
|
||||
handleKeyboardEvent(nil, nil, keycodeMap["`"], [.option], false)
|
||||
XCTAssertEqual(ControlsTab.shortcutsActionsTriggered, ["nextWindowShortcut", "nextWindowShortcut2"])
|
||||
handleKeyboardEvent(nil, nil, nil, [.option], false)
|
||||
XCTAssertEqual(ControlsTab.shortcutsActionsTriggered, ["nextWindowShortcut", "nextWindowShortcut2"])
|
||||
ModifierFlags.current = []
|
||||
handleKeyboardEvent(nil, nil, nil, [], false)
|
||||
XCTAssertEqual(ControlsTab.shortcutsActionsTriggered, ["nextWindowShortcut", "nextWindowShortcut2", "holdShortcut2"])
|
||||
}
|
||||
|
||||
private func resetState() {
|
||||
App.app.appIsBeingUsed = false
|
||||
App.app.shortcutIndex = 0
|
||||
for i in 0..<Preferences.shortcutStyle.count {
|
||||
Preferences.shortcutStyle[i] = .focusOnRelease
|
||||
}
|
||||
ControlsTab.shortcuts.values.forEach { $0.state = .up }
|
||||
ControlsTab.shortcutsActionsTriggered = []
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ class ControlsTab {
|
||||
}
|
||||
if action.starts(with: "nextWindowShortcut") {
|
||||
App.app.appIsBeingUsed = true
|
||||
App.app.shortcutIndex = Preferences.nameToIndex(action)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,6 +67,11 @@ class Preferences {
|
||||
static func indexToName(_ baseName: String, _ index: Int) -> String {
|
||||
return baseName + (index == 0 ? "" : String(index + 1))
|
||||
}
|
||||
|
||||
static func nameToIndex(_ name: String) -> Int {
|
||||
guard let number = name.last?.wholeNumberValue else { return 0 }
|
||||
return number - 1
|
||||
}
|
||||
}
|
||||
|
||||
enum ShortcutStylePreference: CaseIterable {
|
||||
|
||||
Reference in new issue
Block a user