copy_to_clipboard format types

pull/9418/head
Mitchell Hashimoto 2025-10-30 13:30:37 -07:00
parent 77b038dcb6
commit df037d75a6
No known key found for this signature in database
GPG Key ID: 523D5DC389D273BC
3 changed files with 47 additions and 8 deletions

View File

@ -5651,12 +5651,12 @@ pub const Keybinds = struct {
try self.set.put(
alloc,
.{ .key = .{ .physical = .copy } },
.{ .copy_to_clipboard = {} },
.{ .copy_to_clipboard = .mixed },
);
try self.set.put(
alloc,
.{ .key = .{ .physical = .paste } },
.{ .paste_from_clipboard = {} },
.paste_from_clipboard,
);
// On non-MacOS desktop envs (Windows, KDE, Gnome, Xfce), ctrl+insert is an
@ -5669,7 +5669,7 @@ pub const Keybinds = struct {
try self.set.put(
alloc,
.{ .key = .{ .physical = .insert }, .mods = .{ .ctrl = true } },
.{ .copy_to_clipboard = {} },
.{ .copy_to_clipboard = .mixed },
);
try self.set.put(
alloc,
@ -5688,7 +5688,7 @@ pub const Keybinds = struct {
try self.set.putFlags(
alloc,
.{ .key = .{ .unicode = 'c' }, .mods = mods },
.{ .copy_to_clipboard = {} },
.{ .copy_to_clipboard = .mixed },
.{ .performable = true },
);
try self.set.put(

View File

@ -296,7 +296,7 @@ pub const Action = union(enum) {
reset,
/// Copy the selected text to the clipboard.
copy_to_clipboard,
copy_to_clipboard: CopyToClipboard,
/// Paste the contents of the default clipboard.
paste_from_clipboard,
@ -889,6 +889,19 @@ pub const Action = union(enum) {
u16,
};
pub const CopyToClipboard = enum {
plain,
vt,
html,
/// This type will mix multiple distinct types with a set content-type
/// such as text/html for html, so that the OS/application can choose
/// what is best when pasting.
mixed,
pub const default: CopyToClipboard = .mixed;
};
pub const WriteScreenAction = enum {
copy,
paste,
@ -3239,6 +3252,28 @@ test "parse: set_font_size" {
}
}
test "parse: copy to clipboard default" {
const testing = std.testing;
// parameter
{
const binding = try parseSingle("a=copy_to_clipboard");
try testing.expect(binding.action == .copy_to_clipboard);
try testing.expectEqual(Action.CopyToClipboard.mixed, binding.action.copy_to_clipboard);
}
}
test "parse: copy to clipboard explicit" {
const testing = std.testing;
// parameter
{
const binding = try parseSingle("a=copy_to_clipboard:html");
try testing.expect(binding.action == .copy_to_clipboard);
try testing.expectEqual(Action.CopyToClipboard.html, binding.action.copy_to_clipboard);
}
}
test "action: format" {
const testing = std.testing;
const alloc = testing.allocator;

View File

@ -121,11 +121,15 @@ fn actionCommands(action: Action.Key) []const Command {
.description = "Reset the terminal to a clean state.",
}},
.copy_to_clipboard => comptime &.{.{
.action = .copy_to_clipboard,
.copy_to_clipboard => comptime &.{ .{
.action = .{ .copy_to_clipboard = .mixed },
.title = "Copy to Clipboard",
.description = "Copy the selected text to the clipboard.",
}},
}, .{
.action = .{ .copy_to_clipboard = .html },
.title = "Copy HTML to Clipboard",
.description = "Copy the selected text as HTML to the clipboard.",
} },
.copy_url_to_clipboard => comptime &.{.{
.action = .copy_url_to_clipboard,