Skip to content

Commit ef5c34e

Browse files
committed
PR comments
1 parent 2503927 commit ef5c34e

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

Sources/KeyboardShortcuts/Recorder.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ extension KeyboardShortcuts {
2424
}
2525
}
2626
```
27+
28+
An optional onChange callback can be set on the Recorder which will be called when the shortcut is sucessfully changed/removed.
29+
30+
This could be useful if you would like to store the keyboard shortcut somewhere yourself instead of rely on the build-in `UserDefaults` storage.
31+
32+
```
33+
KeyboardShortcuts.Recorder(for: .toggleUnicornMode, onChange: { (shortcut: KeyboardShortcuts.Shortcut?) in
34+
print("Changed shortcut to:", shortcut)
35+
})
36+
```
2737
*/
2838
public struct Recorder: NSViewRepresentable { // swiftlint:disable:this type_name
2939
/// :nodoc:

Sources/KeyboardShortcuts/RecorderCocoa.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ extension KeyboardShortcuts {
2424
}
2525
}
2626
```
27+
28+
An optional onChange callback can be set on the Recorder which will be called when the shortcut is sucessfully changed/removed.
29+
30+
This could be useful if you would like to store the keyboard shortcut somewhere yourself instead of rely on the build-in `UserDefaults` storage.
31+
32+
```
33+
KeyboardShortcuts.RecorderCocoa(for: .toggleUnicornMode, onChange: { (shortcut: KeyboardShortcuts.Shortcut?) in
34+
print("Changed shortcut to:", shortcut)
35+
})
36+
```
2737
*/
2838
public final class RecorderCocoa: NSSearchField, NSSearchFieldDelegate {
2939
private let minimumWidth: Double = 130
@@ -224,9 +234,7 @@ extension KeyboardShortcuts {
224234
userDefaultsRemove(name: shortcutName)
225235
}
226236

227-
if let onChange = self.onChange {
228-
onChange(shortcut)
229-
}
237+
onChange?(shortcut)
230238
}
231239
}
232240
}

0 commit comments

Comments
 (0)