Add method to remove all handlers (#36)

Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
This commit is contained in:
Pedro José Pereira Vieito 2021-01-11 12:24:13 +01:00 committed by GitHub
parent 02a18776d9
commit d8a9321c4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 0 deletions

View File

@ -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.