Skip to content

Fix Cmd+C copy in Quick Look preview#182

Open
sensebat wants to merge 1 commit intosbarex:mainfrom
sensebat:fix/cmd-c-copy
Open

Fix Cmd+C copy in Quick Look preview#182
sensebat wants to merge 1 commit intosbarex:mainfrom
sensebat:fix/cmd-c-copy

Conversation

@sensebat
Copy link

Fixes #177

Problem

Cmd+C doesn't work in Quick Look preview on macOS Tahoe 26.2+, while right-click copy works fine.

Root Cause

Two issues combined to prevent keyboard input:

  1. MyWKWebView explicitly blocked keyboard focus by returning false for canBecomeKeyView and becomeFirstResponder
  2. With QLIsDataBasedPreview=true, macOS 12+ uses the providePreview method which bypasses our WKWebView entirely, giving us no control over keyboard handling

Fix

  1. Allow MyWKWebView to become first responder
  2. Set QLIsDataBasedPreview=false to use the preparePreviewOfFile code path where our WKWebView handles the preview

Testing

  • Select text and press Cmd+C — text is copied to clipboard
  • Right-click copy still works
  • Preview rendering unchanged

Changes

  • QLExtension/PreviewViewController.swift: MyWKWebView now returns true for canBecomeKeyView and becomeFirstResponder
  • QLExtension/Info.plist: QLIsDataBasedPreview set to false

Allow WKWebView to become first responder and use the view-based preview
path instead of the data-based path. This enables keyboard shortcuts
including Cmd+C to work in the Quick Look preview.

Previously, MyWKWebView explicitly returned false for canBecomeKeyView
and becomeFirstResponder, which blocked all keyboard input. Additionally,
with QLIsDataBasedPreview=true, macOS 12+ used the providePreview method
which doesn't use the WKWebView at all, giving us no control over
keyboard handling.

By setting QLIsDataBasedPreview=false and allowing the WebView to become
first responder, Quick Look now uses preparePreviewOfFile with our
WKWebView, and Cmd+C works correctly.

Fixes sbarex#177
@sbarex
Copy link
Owner

sbarex commented Jan 28, 2026

On my system (Tahoe 26.2), the Cmd+C shortcut works correctly! So it seems that the problem must be sought elsewhere…

Setting QLIsDataBasedPreview = true saves the overhead of initializing a custom interface by instructing the operating system to use the default view for the type of data provided (html in this case).

For this reason, I don't want to change this setting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cmd+C for Copy does not work

2 participants