Skip to content

Comments

macos: pass through paste keybind when clipboard has no text#10907

Open
juniqlim wants to merge 6 commits intoghostty-org:mainfrom
juniqlim:macos-performable-paste
Open

macos: pass through paste keybind when clipboard has no text#10907
juniqlim wants to merge 6 commits intoghostty-org:mainfrom
juniqlim:macos-performable-paste

Conversation

@juniqlim
Copy link

@juniqlim juniqlim commented Feb 21, 2026

Closes #10751

Problem

On macOS, when the clipboard contains only an image, pressing Cmd+V is 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_cb to return whether a request was started:

  • ghostty_runtime_read_clipboard_cb now returns bool
  • it now receives ghostty_clipboard_request_e so the host can branch by request type (paste, osc_52_*)

This allows clipboardRequest() to return false immediately for non-started paste requests, which is what performable keybind pass-through needs.

2. Swift implementation (Ghostty.App.swift)
readClipboard now performs a synchronous precheck for paste requests. If the pasteboard has no text-like content, it returns false immediately (no async completion call), so the keypress passes through.

3. Lightweight text-content detection (NSPasteboard+Extension.swift)
hasTextContent() now uses NSPasteboard.availableType(from:) (string/url/file-url type presence) instead of calling getOpinionatedStringContents(), 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+V with Cmd+C:

  • copy_to_clipboard already uses a performable binding.
  • This PR makes paste_from_clipboard performable as well.

Performable bindings are not shown as menu shortcut labels, so Cmd+V may 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 test

Manual 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.

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>
@juniqlim juniqlim requested a review from a team as a code owner February 21, 2026 00:14
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.

macOS: performable paste_from_clipboard (parity with GTK #10089)

1 participant