Skip to content

Ghostty terminal: mouse position offset causes incorrect text selection and click targeting #4

@dhilgaertner

Description

@dhilgaertner

Problem

Mouse interactions in the embedded Ghostty terminal are misaligned — the cursor position the terminal registers doesn't match where the user is actually clicking/dragging. This manifests as:

  1. Drag-to-select selects wrong text — dragging over visible text highlights a different region than what's under the cursor
  2. Double-click doesn't highlight the target word/link — double-clicking on a link or word either selects nothing or selects adjacent content instead
  3. General click targeting is off — there appears to be a spatial offset between the macOS mouse position and where Ghostty thinks the click landed

Expected Behavior

  • Drag selection should highlight exactly the text under the cursor
  • Double-click should select the word or link directly under the pointer
  • Click-to-place-cursor should position the terminal cursor at the clicked location

Likely Cause

This is likely a coordinate translation issue between the SwiftUI/AppKit view hierarchy and the Ghostty surface. Common causes:

  • Title bar or toolbar offset — if the terminal surface doesn't account for the window's title bar, toolbar, or tab bar height, all coordinates will be shifted vertically
  • Retina/scale factor — mismatch between logical points and pixel coordinates on HiDPI displays
  • Safe area insets or padding — extra padding around the terminal view not accounted for in hit testing
  • SwiftUI view embedding — if Ghostty is embedded via NSViewRepresentable or similar, the coordinate space translation between SwiftUI and the underlying NSView may be incorrect

Reproduction

  1. Open any session with a Ghostty terminal containing text
  2. Try to select text by clicking and dragging — observe that the selection doesn't match cursor position
  3. Double-click on a word or URL — observe it doesn't highlight the expected target

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions