From a0d488cc9d680b74dc4cb89fbda44b8922ea2516 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1rady=20Mil=C3=A1n?= <61704770+MilanVarady@users.noreply.github.com> Date: Tue, 5 Nov 2024 16:49:22 +0100 Subject: [PATCH] Fix conf shortcut behavior --- .../ConfigurationContextMenuView.swift | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Source/Marker Data/Marker Data/Views/Detail Views/Configurations/ConfigurationContextMenuView.swift b/Source/Marker Data/Marker Data/Views/Detail Views/Configurations/ConfigurationContextMenuView.swift index b30517f..187133e 100644 --- a/Source/Marker Data/Marker Data/Views/Detail Views/Configurations/ConfigurationContextMenuView.swift +++ b/Source/Marker Data/Marker Data/Views/Detail Views/Configurations/ConfigurationContextMenuView.swift @@ -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)") } } }