Skip to content

Commit

Permalink
Add more button shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsaidi committed Jan 20, 2025
1 parent 0883c18 commit 546c0ef
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
7 changes: 7 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ SwiftUIKit makes its best effort to honor semver, but breaking changes can occur



## 5.1.1

### ✨ Features

* `StandardButtonType` adds even more standard button shortcuts.


## 5.1

### ✨ Features
Expand Down
20 changes: 9 additions & 11 deletions Sources/SwiftUIKit/Buttons/StandardButtonType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,18 @@ public extension ButtonType {
}

#if os(iOS) || os(macOS)
var keyboardShortcut: KeyEquivalent? {
var keyboardShortcut: (key: KeyEquivalent, modifiers: EventModifiers?)? {
switch self {
case .search: "f"
case .add: ("a", .command)
case .cancel: (.escape, nil)
case .done: (.return, .command)
case .edit: ("e", .command)
case .search: ("f", .command)
default: nil
}
}
#endif

var keyboardShortcutModifier: EventModifiers? {
switch self {
default: .command
}
}

var role: ButtonRole? {
switch self {
case .cancel: .cancel
Expand Down Expand Up @@ -128,10 +126,10 @@ public extension View {
) -> some View {
#if os(iOS) || os(macOS)
if let shortcut = button.keyboardShortcut {
if let modifier = button.keyboardShortcutModifier {
self.keyboardShortcut(shortcut, modifiers: modifier)
if let modifiers = shortcut.modifiers {
self.keyboardShortcut(shortcut.key, modifiers: modifiers)
} else {
self.keyboardShortcut(shortcut)
self.keyboardShortcut(shortcut.key)
}
} else {
self
Expand Down

0 comments on commit 546c0ef

Please sign in to comment.