quickLookPreview keyboard issues on macOS

I'm trying to add QuickLook previews to a SwiftUI app which uses Table().

I've added the .quickLookPreview() modifier to my Table(), and added a menu command for invoking it, and if I select that menu item manually, it works fine, but I have two keyboard related issues which are making it difficult to actually ship this functionality:

  1. When using the .quickLookPreview() variant for a set of URLs, keyboard navigation between the quicklook previews only works with left/right arrows, but being invoked by a Table, it would make much more sense for up/down arrows to navigate through the previews
  2. I set a .keyboardShortcut() on the menu command to use Space, since that's the normally-expected shortcut for quicklook, and it doesn't work. If I set it to some random other key (like "a") it does work, but .space doesn't do anything.
Answered by cmsj in 792440022

Doh, I'd forgotten about .onKeyPress(). Adding this onto my Table() works fine:

        .onKeyPress(.space, action: {
            viewModel.extractForQuicklook()
            return .handled
        })
            CommandGroup(after: .sidebar) {
                Button("Quicklook") {
                    guard activeViewModel != nil else { return }
                    activeViewModel?.extractForQuicklook()
                }
                .keyboardShortcut(.space, modifiers: []) // FIXME: This doesn't work if it's .space, but does work if it's "a"
                .disabled(activeViewModel?.selectedEntries.count == 0)
                Divider()
            }

This is how I'm trying to set Space as the keyboard shortcut.

Accepted Answer

Doh, I'd forgotten about .onKeyPress(). Adding this onto my Table() works fine:

        .onKeyPress(.space, action: {
            viewModel.extractForQuicklook()
            return .handled
        })
quickLookPreview keyboard issues on macOS
 
 
Q