Skip to content

Commit 0469a9d

Browse files
Fix copy-on-select: override to clipboard and update ghostty fork
Override copy-on-select = clipboard so that selecting text in the terminal copies to the system clipboard (NSPasteboard.general), matching macOS user expectations. Ghostty's default of .true writes to a private named pasteboard that is not accessible via Cmd+V. Update the ghostty submodule to include the fix for the use-after-free in the mouse release copy-on-select path (manaflow-ai/ghostty#36). Update docs/ghostty-fork.md with section 8 documenting the fork change. Fixes manaflow-ai#2664
1 parent 34fcc42 commit 0469a9d

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

Sources/GhosttyTerminalView.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1708,6 +1708,17 @@ class GhosttyApp {
17081708
ghostty_config_load_recursive_files(config)
17091709
loadCmuxAppSupportGhosttyConfigIfNeeded(config)
17101710
loadCJKFontFallbackIfNeeded(config)
1711+
// Ghostty's default copy-on-select = true writes to a private
1712+
// named pasteboard (com.mitchellh.ghostty.selection) that is not
1713+
// the system clipboard. Override to "clipboard" so that selecting
1714+
// text copies to NSPasteboard.general and Cmd+V works as macOS
1715+
// users expect.
1716+
loadInlineGhosttyConfig(
1717+
"copy-on-select = clipboard",
1718+
into: config,
1719+
prefix: "cmux-copy-on-select",
1720+
logLabel: "copy-on-select override"
1721+
)
17111722
let useHostLayerBackground = !hasConfiguredBackgroundImage(config)
17121723
usesHostLayerBackground = useHostLayerBackground
17131724
if !useHostLayerBackground {

docs/ghostty-fork.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ When we change the fork, update this document and the parent submodule SHA.
1313
## Current fork changes
1414

1515
Fork rebased onto upstream `main` at `3509ccf78` (`v1.3.1-457-g3509ccf78`) on March 30, 2026.
16-
Current cmux pinned fork head: `ae3cc5d29` (`v1.3.1-473-gae3cc5d29`).
16+
Current cmux pinned fork head: `75ec7bf89` (`fix-copy-on-select-uaf`).
1717
Fork `main` keeps this pin reachable via merge commit `5c781d710`
1818
(`Retain layer-background pin ancestry on main`).
1919

@@ -112,7 +112,17 @@ tend to conflict together during rebases.
112112
- Allows the host app to provide the terminal background via `CALayer.backgroundColor` for instant coverage during view resizes, avoiding alpha double-stacking.
113113
- Replays the layer-background restore on top of the refreshed Ghostty base so cmux keeps the resize-coverage fix after the upstream sync.
114114

115-
The fork branch HEAD is now the section 7 layer-background restore commit.
115+
The fork branch HEAD is now the section 8 copy-on-select fix commit.
116+
117+
### 8) Fix use-after-free in copy-on-select mouse release path
118+
119+
- Commit: `75ec7bf89` (Fix use-after-free in copy-on-select mouse release path)
120+
- Files:
121+
- `src/Surface.zig`
122+
- Summary:
123+
- Fixes a use-after-free in `mouseButtonCallback` when the left mouse button is released after a drag selection.
124+
- The old code called `setSelection()` which freed tracked pins via `Screen.select()` then compared the new selection against the freed `prev` pointer via `eql()`. Since freed memory usually retains old values, `eql()` returned true and `copySelectionToClipboards` was silently skipped.
125+
- The fix reads the existing tracked selection directly and calls `copySelectionToClipboards` without going through `setSelection()`, since the mouse release path does not need to change the selection.
116126

117127
## Upstreamed fork changes
118128

ghostty

0 commit comments

Comments
 (0)