From 50e8ebaf6025c4b35ef57f0e82418e4beb3e3db3 Mon Sep 17 00:00:00 2001 From: 007hacky007 <007hacky007@users.noreply.github.com> Date: Mon, 20 Apr 2026 19:56:45 +0200 Subject: [PATCH] surface: sync middle-click paste source with copy-on-select Middle-click paste previously always read from the selection clipboard (falling back to the standard clipboard on platforms without one). Now the paste source follows copy-on-select: - copy-on-select = true: paste from selection clipboard (unchanged) - copy-on-select = clipboard: paste from system clipboard - copy-on-select = false: paste from selection clipboard (unchanged) Fixes ghostty-org/ghostty#9788. --- src/Surface.zig | 17 ++++++++++++----- src/config/Config.zig | 7 +++++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/Surface.zig b/src/Surface.zig index dfc3a50ea..c9f49a836 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -4007,12 +4007,19 @@ pub fn mouseButtonCallback( } } - // Middle-click pastes from our selection clipboard + // Middle-click paste source follows copy-on-select: when copy-on-select + // targets the selection clipboard, middle-click reads from it; when + // copy-on-select targets the system clipboard, middle-click reads from + // that instead. Falls back to the standard clipboard on platforms that + // do not support the selection clipboard. if (button == .middle and action == .press) { - const clipboard: apprt.Clipboard = if (self.rt_surface.supportsClipboard(.selection)) - .selection - else - .standard; + const clipboard: apprt.Clipboard = switch (self.config.copy_on_select) { + .clipboard => .standard, + .true, .false => if (self.rt_surface.supportsClipboard(.selection)) + .selection + else + .standard, + }; _ = try self.startClipboardRequest(clipboard, .{ .paste = {} }); } diff --git a/src/config/Config.zig b/src/config/Config.zig index 13f78eea6..aedb8bd76 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -2404,8 +2404,11 @@ keybind: Keybinds = .{}, /// The value `clipboard` will always copy text to the selection clipboard /// as well as the system clipboard. /// -/// Middle-click paste will always use the selection clipboard. Middle-click -/// paste is always enabled even if this is `false`. +/// Middle-click paste is always enabled even if this is `false`. The +/// clipboard it pastes from follows this setting: with `true` (or `false`) +/// it reads from the selection clipboard (falling back to the system +/// clipboard on platforms without a selection clipboard); with `clipboard` +/// it reads from the system clipboard. /// /// The default value is true on Linux and macOS. @"copy-on-select": CopyOnSelect = switch (builtin.os.tag) {