copy-on-select = clipboard ONLY copies text as mixed types (html & plain) - would like to control this #12971
Replies: 6 comments 1 reply
|
Just for proof of concept purposes, I have been testing locally just to verify that what I am seeing is indeed happening and I did a quick feature (which might not be the best way to implement this if it were to be adopted as a feature) to add a config option to allow me to configure the copy-on-select to be plain (also in https://github.com/mbentley/ghostty/tree/copy-on-select-plain): diff --git a/src/Surface.zig b/src/Surface.zig
index c56c9791c..8b21dd3e1 100644
--- a/src/Surface.zig
+++ b/src/Surface.zig
@@ -301,6 +301,7 @@ const DerivedConfig = struct {
clipboard_paste_bracketed_safe: bool,
clipboard_codepoint_map: configpkg.Config.RepeatableClipboardCodepointMap,
copy_on_select: configpkg.CopyOnSelect,
+ copy_on_select_format: input.Binding.Action.CopyToClipboard,
right_click_action: configpkg.RightClickAction,
middle_click_action: configpkg.MiddleClickAction,
confirm_close_surface: configpkg.ConfirmCloseSurface,
@@ -380,6 +381,7 @@ const DerivedConfig = struct {
.clipboard_paste_bracketed_safe = config.@"clipboard-paste-bracketed-safe",
.clipboard_codepoint_map = try config.@"clipboard-codepoint-map".clone(alloc),
.copy_on_select = config.@"copy-on-select",
+ .copy_on_select_format = config.@"copy-on-select-format",
.right_click_action = config.@"right-click-action",
.middle_click_action = config.@"middle-click-action",
.confirm_close_surface = config.@"confirm-close-surface",
@@ -2373,7 +2375,7 @@ fn setSelectionAndCopy(self: *Surface, sel: terminal.Selection) !void {
.clipboard => try self.copySelectionToClipboards(
sel,
&.{ .standard, .selection },
- .mixed,
+ self.config.copy_on_select_format,
),
// The selection clipboard is set if supported, otherwise the standard.
@@ -2385,7 +2387,7 @@ fn setSelectionAndCopy(self: *Surface, sel: terminal.Selection) !void {
try self.copySelectionToClipboards(
sel,
&.{clipboard},
- .mixed,
+ self.config.copy_on_select_format,
);
},
}
diff --git a/src/config/Config.zig b/src/config/Config.zig
index 66b8c6057..a7177d78a 100644
--- a/src/config/Config.zig
+++ b/src/config/Config.zig
@@ -2419,6 +2419,20 @@ keybind: Keybinds = .{},
else => .false,
},
+/// The clipboard format used when copying text via `copy-on-select`.
+///
+/// Valid values:
+///
+/// * `mixed` - Copy as both plain text and HTML, allowing the receiving
+/// application to choose the appropriate format. This is the default.
+/// * `plain` - Copy as plain text only. Use this to prevent applications
+/// from receiving styled/HTML content when pasting.
+/// * `vt` - Copy with ANSI escape sequences preserved.
+/// * `html` - Copy as HTML only.
+///
+/// The default value is `mixed`.
+@"copy-on-select-format": inputpkg.Binding.Action.CopyToClipboard = .mixed,
+
/// The action to take when the user right-clicks on the terminal surface.
///
/// Valid values: |
|
I'm also hitting this issue. When using @mbentley's proposal sounds good to me! |
|
Same here on macOS, pasting into Microsoft Teams. copy-on-select always includes the Context on why this started: #9418 added a format parameter to the The HTML is emitted as Proposal (same as OP): let copy-on-select take a format, or add a separate option, defaulting to |
|
Same on NixOS. Copy-on-select from ghostty and pasting on Claude web and some other sites garbles all newlines, due to the default (and un-modifiable) being html. The Really hoping to see a configurable |
|
Hey folks, I'm relatively new to ghostty, however I've been experimenting with different terminals as of late and generally found that I really like this one. I seemingly, however, this very problem. I'm a debian + gnome desktop user, and I pretty habitually use both keyboard shortcuts and middle mouse click to paste. I've added this to the config file which solves the keyboard shortcut issue keybind = ctrl+shift+c=copy_to_clipboard:plain but middle mouse button is still doing the mix format messages and essentially pasting garbage into text fields that don't support it. I'm going to see about integrating @mbentley 's suggestion on a custom compiled version to get around this for now, but would love to see this added officially. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Issue Description
Sorry if this should be considered to be more of a feature instead of a bug. I'm not sure if this is anticipated behavior or not. When using
copy-on-select = clipboard, if the selection I have in the clipboard is formatted, it's being copied as html.Copying the same text when using iTerm2, I get it copied as plain text:
This is problematic because in some applications, such as Obsidian or other apps that can paste rich text, you get unexpected output while I would always like plain text to be copied from a terminal application.
Expected Behavior
I would like to be able to control the ability to copy as plain text.
It would be great if this could be controlled in a similar fashion to:
When copying using super+c with the above config, it copies as expected:
You can also see it pastes as I would expect in my example using Obsidian to paste:

It would be ideal if the same control could be done for copying on select
I believe this was added in #9397
Actual Behavior
There is no setting that controls whether what is copied is HTML or plain (or mixed) to the best of my understanding.
Reproduction Steps
osascript -e 'clipboard info'to see this).Here is an example where I am copying the text

config.ghostty@where there is different formatting. The different formatting is key for where the paste pastes funny:Here is an example of it pasting funny in an app where it's adding extra lines (this is Obsidian but it also happens in other things like when pasting text into the Claude web interface, for example):

Ghostty Logs
Ghostty Version
OS Version Information
macOS Tahoe 26.5.1
(Linux only) Display Server
None
(Linux only) Desktop Environment/Window Manager
No response
Minimal Ghostty Configuration
copy-on-select = clipboardAdditional Relevant Configuration
Just in case it is relevant, I use bash + starship in my terminal.
I acknowledge that:
```) on separate lines.All reactions