Terminal: add macOS dictionary Look Up (three-finger tap / ⌃⌘D / force-click)

JI
2mo ago
+40-0

Summary

Adds macOS dictionary Look Up for terminal text — three-finger tap, force-click, and ⌃⌘D now show the system definition popover for the word under the cursor, matching upstream Ghostty and Terminal.app / iTerm2. Fixes #8237.

What was missing

GhosttyNSView (the macOS terminal view) didn't override the quickLook(with:) NSResponder method, so the OS Look-Up gesture/shortcut had nothing to invoke over terminal text. The existing ghostty_surface_quicklook_word call in resolveWordUnderCursorPath is cmd-click path resolution; other quickLook references are the file-preview feature — neither is dictionary look-up.

Change

Override quickLook(with:) on GhosttyNSView, mirroring upstream Ghostty's SurfaceView. It reuses libghostty quicklook APIs the project already links (ghostty_surface_quicklook_word / ghostty_surface_quicklook_font / ghostty_surface_free_text), so no ghostty-submodule change is needed. One file, +33 lines.

Testing

⚠️ Not built/tested locally — I don't have the cmux build toolchain (Xcode + Zig) on this machine. The change:

  • passes swiftc -parse (no syntax errors),
  • mirrors upstream Ghostty's proven implementation almost verbatim, and
  • only calls libghostty APIs already used elsewhere in this file.

Opening as a draft so CI and a maintainer can validate the build and confirm the popover appears. Happy to adjust.

Manual verification

  1. System Settings → Trackpad → Point & Click → "Look up & data detectors" = Tap with three fingers.
  2. In a terminal, hover a word and three-finger tap (or press ⌃⌘D, or force-click).
  3. The macOS definition popover should appear for that word.

View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.


Summary by cubic

Enable macOS Dictionary Look Up in the terminal: three-finger tap, force-click, and ⌃⌘D now show the system definition popover for the word under the cursor, matching Ghostty upstream and Terminal.app/iTerm2. Fixes #8237.

  • New Features

    • Override quickLook(with:) on GhosttyNSView to trigger Look Up at the cursor.
    • Reuse existing libghostty APIs: ghostty_surface_quicklook_word, ghostty_surface_quicklook_font, ghostty_surface_free_text (no submodule changes).
    • Apply the terminal's primary font for the popover.
  • Bug Fixes

    • Decode the word with text_len (length-counted, not NUL-terminated) and use Unmanaged.takeRetainedValue() for the CTFont (Create rule).
    • Use bounds.height for the y-flip during coordinate conversion to fix popover positioning.
    • Validate the live terminal surface and fall back to standard Quick Look when the surface or word is unavailable.

Summary by CodeRabbit

  • New Features
    • Added macOS Look Up/Quick Look support for words beneath the terminal cursor, displaying the corresponding definition.
    • Definitions can use the terminal’s font styling for a more consistent appearance.
    • Standard macOS Quick Look remains available when the terminal cannot provide a word or the lookup returns no usable text, preserving the usual system behavior in those cases.