Skip to content

Commit

Permalink
Add method to remove all handlers (#36)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
  • Loading branch information
pvieito and sindresorhus committed Jan 11, 2021
1 parent 02a1877 commit d8a9321
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Sources/KeyboardShortcuts/KeyboardShortcuts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit d8a9321

Please sign in to comment.