macOS: command palette "enter" works

pull/7153/head
Mitchell Hashimoto 2025-04-21 09:32:39 -07:00
parent 0915a7af46
commit afd4ec6de2
No known key found for this signature in database
GPG Key ID: 523D5DC389D273BC
1 changed files with 13 additions and 3 deletions

View File

@ -55,6 +55,9 @@ struct CommandPaletteView: View {
case .submit:
isPresented = false
if selectedIndex < filteredOptions.count {
filteredOptions[Int(selectedIndex)].action()
}
case .move(.up):
if selectedIndex > 0 {
@ -79,7 +82,10 @@ struct CommandPaletteView: View {
options: options,
query: $query,
selectedIndex: $selectedIndex,
hoveredOptionID: $hoveredOptionID)
hoveredOptionID: $hoveredOptionID) { option in
isPresented = false
option.action()
}
}
.frame(width: 500)
.background(backgroundColor)
@ -146,6 +152,7 @@ fileprivate struct CommandTable: View {
@Binding var query: String
@Binding var selectedIndex: UInt
@Binding var hoveredOptionID: UUID?
var action: (CommandOption) -> Void
// The options that we should show, taking into account any filtering from
// the query.
@ -171,7 +178,9 @@ fileprivate struct CommandTable: View {
option: option,
isSelected: selectedIndex == index,
hoveredID: $hoveredOptionID
)
) {
action(option)
}
}
}
}
@ -194,9 +203,10 @@ fileprivate struct CommandRow: View {
let option: CommandOption
var isSelected: Bool
@Binding var hoveredID: UUID?
var action: () -> Void
var body: some View {
Button(action: option.action) {
Button(action: action) {
HStack {
Text(option.title.lowercased())
Spacer()