Skip to content

Commit

Permalink
Fix conf shortcut behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
milanvarady committed Nov 5, 2024
1 parent 17eef44 commit a0d488c
Showing 1 changed file with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,26 @@ struct ConfigurationContextMenuView: View {
Menu {
ForEach(Array(settings.keyboardShortcuts.enumerated()), id: \.offset) { index, confName in
Button {
settings.keyboardShortcuts[index] = if settings.keyboardShortcuts[index] == store.name {
"" // Unassign shortcut
if settings.keyboardShortcuts[index] == store.name {
// Unassign shortcut
settings.keyboardShortcuts[index] = ""
} else {
store.name // Assign shortcut
// Remove previous bindings
settings.keyboardShortcuts = settings.keyboardShortcuts.map { $0 == store.name ? "" : $0 }
// Assign shortcut
settings.keyboardShortcuts[index] = store.name
}

// Call objectWillChange manually as keyboardShortcuts is not a published property
settings.objectWillChange.send()
} label: {
// We have to add the tick symbol this a hacky way because
// the Menu view ignores any other types layout modifiers
HStack {
Label("\(index + 1)", systemImage: confName == store.name ? "checkmark" : "command")
.tag(index)
// Tick or space
Text(confName == store.name ? "" : String(repeating: " ", count: 4)) +
// Shortcut
Text("\(index + 1)")
}
}
}
Expand Down

0 comments on commit a0d488c

Please sign in to comment.