From d8a9321c4a2c39363b7c1d57d86d8d24f7f5cfc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Jos=C3=A9=20Pereira=20Vieito?= Date: Mon, 11 Jan 2021 12:24:13 +0100 Subject: [PATCH] Add method to remove all handlers (#36) Co-authored-by: Sindre Sorhus --- Sources/KeyboardShortcuts/KeyboardShortcuts.swift | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Sources/KeyboardShortcuts/KeyboardShortcuts.swift b/Sources/KeyboardShortcuts/KeyboardShortcuts.swift index de9a2ffc..ae393f36 100644 --- a/Sources/KeyboardShortcuts/KeyboardShortcuts.swift +++ b/Sources/KeyboardShortcuts/KeyboardShortcuts.swift @@ -46,6 +46,18 @@ public enum KeyboardShortcuts { // TODO: Should remove user defaults too. } + /** + Remove all handlers receiving keyboard shortcuts events. + + This can be used to reset the handlers before re-creating them to avoid having multiple handlers for the same shortcut. + */ + public static func removeAllHandlers() { + keyDownHandlers = [:] + keyUpHandlers = [:] + userDefaultsKeyDownHandlers = [:] + userDefaultsKeyUpHandlers = [:] + } + // TODO: Also add `.isEnabled(_ name: Name)`. /** Disable a keyboard shortcut.