From 83b53194334d566c395e395ca4c850517d149d3f Mon Sep 17 00:00:00 2001 From: lwouis Date: Tue, 3 Dec 2024 22:38:39 +0100 Subject: [PATCH] fix: [after release: do nothing] was broken in v7.6.0 (closes #3929) --- src/logic/ATShortcut.swift | 2 +- unit-tests/KeyboardEventsTests.swift | 37 ++++++++++++++++++++++++++++ unit-tests/Mocks.swift | 6 +++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/logic/ATShortcut.swift b/src/logic/ATShortcut.swift index ff27d46d..2d957d65 100644 --- a/src/logic/ATShortcut.swift +++ b/src/logic/ATShortcut.swift @@ -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) diff --git a/unit-tests/KeyboardEventsTests.swift b/unit-tests/KeyboardEventsTests.swift index 1e360e46..3100a0a0 100644 --- a/unit-tests/KeyboardEventsTests.swift +++ b/unit-tests/KeyboardEventsTests.swift @@ -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.. 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 {