I am having a fairly specific problem with my keyboard shortcuts for my SwiftUI application. I have a set of buttons in my toolbar that correspond to different actions and keys, but the button that uses just .return as its shortcut doesn't work once I enter fullscreen (press the green button to maximize) and even once I exit fullscreen.
Here is a video showing the behavior: link
As you can see both on the button and in the console in the bottom right, the enter key activates the button until I enter fullscreen. I will put code snippets below showing how I have things set up. This is also my first project in Swift so any general help would be great :)
struct ContentView: View {
@Binding var document: OutlinerDocument
var body: some View {
Text("Tree goes here")
.font(.title)
.frame(minWidth: 400, idealWidth: 600, maxWidth: .infinity, minHeight: 300, idealHeight: 400, maxHeight: .infinity, alignment: .center)
.toolbar(content: {
// main buttons to modify the model
HStack(alignment: .bottom) {
ActionButton(imageName: "text.badge.minus", label: "Delete item(s)", customAction: customAction)
.keyboardShortcut(.delete, modifiers: [])
ActionButton(imageName: "text.badge.plus", label: "Add item", customAction: customAction)
.keyboardShortcut(.return, modifiers: [])
ActionButton(imageName: "text.badge.star", label: "Add child", customAction: customAction)
.keyboardShortcut(.return, modifiers: [.shift])
ActionButton(imageName: "arrow.right.to.line", label: "Indent", customAction: customAction)
.keyboardShortcut(.tab, modifiers: [])
ActionButton(imageName: "arrow.left.to.line", label: "Outdent", customAction: customAction)
.keyboardShortcut(.tab, modifiers: [.shift])
}
})
.focusable()
}
}
struct ActionButton: View {
var imageName: String
var label: String
var customAction: () -> Void
var body: some View {
Button(action: customAction, label: {
Image(systemName: imageName)
.font(.title)
})
.help(label)
}
}