Skip to content

Commit 546c0ef

Browse files
committed
Add more button shortcuts
1 parent 0883c18 commit 546c0ef

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

RELEASE_NOTES.md

+7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ SwiftUIKit makes its best effort to honor semver, but breaking changes can occur
44

55

66

7+
## 5.1.1
8+
9+
### ✨ Features
10+
11+
* `StandardButtonType` adds even more standard button shortcuts.
12+
13+
714
## 5.1
815

916
### ✨ Features

Sources/SwiftUIKit/Buttons/StandardButtonType.swift

+9-11
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,18 @@ public extension ButtonType {
7474
}
7575

7676
#if os(iOS) || os(macOS)
77-
var keyboardShortcut: KeyEquivalent? {
77+
var keyboardShortcut: (key: KeyEquivalent, modifiers: EventModifiers?)? {
7878
switch self {
79-
case .search: "f"
79+
case .add: ("a", .command)
80+
case .cancel: (.escape, nil)
81+
case .done: (.return, .command)
82+
case .edit: ("e", .command)
83+
case .search: ("f", .command)
8084
default: nil
8185
}
8286
}
8387
#endif
8488

85-
var keyboardShortcutModifier: EventModifiers? {
86-
switch self {
87-
default: .command
88-
}
89-
}
90-
9189
var role: ButtonRole? {
9290
switch self {
9391
case .cancel: .cancel
@@ -128,10 +126,10 @@ public extension View {
128126
) -> some View {
129127
#if os(iOS) || os(macOS)
130128
if let shortcut = button.keyboardShortcut {
131-
if let modifier = button.keyboardShortcutModifier {
132-
self.keyboardShortcut(shortcut, modifiers: modifier)
129+
if let modifiers = shortcut.modifiers {
130+
self.keyboardShortcut(shortcut.key, modifiers: modifiers)
133131
} else {
134-
self.keyboardShortcut(shortcut)
132+
self.keyboardShortcut(shortcut.key)
135133
}
136134
} else {
137135
self

0 commit comments

Comments
 (0)