macos: pass through paste keybind when clipboard has no text#10907
Open
juniqlim wants to merge 6 commits intoghostty-org:mainfrom
Open
macos: pass through paste keybind when clipboard has no text#10907juniqlim wants to merge 6 commits intoghostty-org:mainfrom
juniqlim wants to merge 6 commits intoghostty-org:mainfrom
Conversation
Port the GTK behavior from ghostty-org#10089 to the embedded apprt. When paste_from_clipboard is triggered but the clipboard contains no text (e.g. only an image), clipboardRequest() now returns false so the performable keybind passes the key through to the application. Changes: - Add clipboard_has_text callback to embedded runtime options - Check clipboard content in clipboardRequest() for paste requests - Make default paste bindings performable Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #10751
Problem
On macOS, when the clipboard contains only an image, pressing
Cmd+Vis consumed by Ghostty even though there's nothing to paste. This prevents TUI apps (e.g. Claude Code) that handle image paste natively from ever receiving the keypress.GTK already handles this correctly (#10089) — this PR brings the same behavior to the embedded apprt.
How it works
1. Embedded runtime callback flow (
ghostty.h,embedded.zig)Instead of adding a separate "has text" callback, this updates
read_clipboard_cbto return whether a request was started:ghostty_runtime_read_clipboard_cbnow returnsboolghostty_clipboard_request_eso the host can branch by request type (paste,osc_52_*)This allows
clipboardRequest()to returnfalseimmediately for non-started paste requests, which is what performable keybind pass-through needs.2. Swift implementation (
Ghostty.App.swift)readClipboardnow performs a synchronous precheck for paste requests. If the pasteboard has no text-like content, it returnsfalseimmediately (no async completion call), so the keypress passes through.3. Lightweight text-content detection (
NSPasteboard+Extension.swift)hasTextContent()now usesNSPasteboard.availableType(from:)(string/url/file-url type presence) instead of callinggetOpinionatedStringContents(), avoiding unnecessary content extraction for a boolean check.4. Enum safety checks (
embedded.zig)Added centralized mapping helpers and compile-time/test checks for clipboard/request enum value sync to reduce silent drift risk.
Menu Shortcut Behavior
This change intentionally aligns
Cmd+VwithCmd+C:copy_to_clipboardalready uses a performable binding.paste_from_clipboardperformable as well.Performable bindings are not shown as menu shortcut labels, so
Cmd+Vmay no longer appear in the menu shortcut label. This is an intentional tradeoff for consistent performable behavior.Testing
zig build test -Dtest-filter='embedded: clipboard enum mapping for runtime callbacks'zig build test -Dtest-filter='embedded: clipboard request enum mapping for runtime callbacks'zig build test -Dtest-filter='default paste keybinds are performable'zig build testManual check on macOS with Claude Code: when clipboard contains only image data, paste keybind passes through and image paste is handled by the TUI app.
AI Usage
This PR was developed with Claude Code assistance.
Codex was used to review this PR and apply follow-up fixes.
The implementation approach and code were written with AI help and manually verified on macOS.