@@ -206,8 +206,8 @@ public enum KeyboardShortcuts {
206
206
legacyKeyUpHandlers = [ : ]
207
207
208
208
// invalidate and remove all elements of userDefaultsObservers
209
- for observation in userDefaultsObservers {
210
- observation . invalidate ( )
209
+ for observer in userDefaultsObservers {
210
+ observer . invalidate ( )
211
211
}
212
212
userDefaultsObservers. removeAll ( )
213
213
}
@@ -441,8 +441,10 @@ public enum KeyboardShortcuts {
441
441
*/
442
442
public static func onKeyDown( for name: Name , action: @escaping ( ) -> Void ) {
443
443
legacyKeyDownHandlers [ name, default: [ ] ] . append ( action)
444
- startObservingShortcutIfNeeded ( for: name)
445
444
registerShortcutIfNeeded ( for: name)
445
+
446
+ // observe changes to the UserDefaults instance for the given shortcut name
447
+ startObservingShortcutIfNeeded ( for: name)
446
448
}
447
449
448
450
/**
@@ -468,8 +470,10 @@ public enum KeyboardShortcuts {
468
470
*/
469
471
public static func onKeyUp( for name: Name , action: @escaping ( ) -> Void ) {
470
472
legacyKeyUpHandlers [ name, default: [ ] ] . append ( action)
471
- startObservingShortcutIfNeeded ( for: name)
472
473
registerShortcutIfNeeded ( for: name)
474
+
475
+ // observe changes to the UserDefaults instance for the given shortcut name
476
+ startObservingShortcutIfNeeded ( for: name)
473
477
}
474
478
475
479
private static let userDefaultsPrefix = " KeyboardShortcuts_ "
@@ -479,9 +483,9 @@ public enum KeyboardShortcuts {
479
483
}
480
484
481
485
/**
482
- Start observing UserDefaults changes for a specific shortcut name.
483
-
484
- This function manages the lifecycle of observations for keyboard shortcuts in the given suite (e.g. UserDefaults ):
486
+ Start observing changes to the ` UserDefaults` instance for a specific shortcut name.
487
+
488
+ This function manages the lifecycle of observations for keyboard shortcuts in the given `UserDefaults` instance (set by `userDefaults` property ):
485
489
- Checks if the shortcut is already being observed
486
490
- If already observed, restarts the observation
487
491
- If not observed, creates a new observation and adds it to the observers list
@@ -610,6 +614,9 @@ extension KeyboardShortcuts {
610
614
}
611
615
612
616
registerShortcutIfNeeded ( for: name)
617
+
618
+ // observe changes to the UserDefaults instance for the given shortcut name
619
+ startObservingShortcutIfNeeded ( for: name)
613
620
}
614
621
615
622
continuation. onTermination = { _ in
0 commit comments