diff --git a/src/Surface.zig b/src/Surface.zig index f7a961b62..bfadb3be8 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -258,6 +258,7 @@ const DerivedConfig = struct { mouse_shift_capture: configpkg.MouseShiftCapture, macos_non_native_fullscreen: configpkg.NonNativeFullscreen, macos_option_as_alt: ?configpkg.OptionAsAlt, + selection_clear_on_copy: bool, selection_clear_on_typing: bool, vt_kam_allowed: bool, wait_after_command: bool, @@ -327,6 +328,7 @@ const DerivedConfig = struct { .mouse_shift_capture = config.@"mouse-shift-capture", .macos_non_native_fullscreen = config.@"macos-non-native-fullscreen", .macos_option_as_alt = config.@"macos-option-as-alt", + .selection_clear_on_copy = config.@"selection-clear-on-copy", .selection_clear_on_typing = config.@"selection-clear-on-typing", .vt_kam_allowed = config.@"vt-kam-allowed", .wait_after_command = config.@"wait-after-command", @@ -4544,6 +4546,17 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !bool return true; }; + // Clear the selection if configured to do so. + if (self.config.selection_clear_on_copy) { + if (self.setSelection(null)) { + self.queueRender() catch |err| { + log.warn("failed to queue render after clear selection err={}", .{err}); + }; + } else |err| { + log.warn("failed to clear selection after copy err={}", .{err}); + } + } + return true; } diff --git a/src/config/Config.zig b/src/config/Config.zig index 384a4f006..019e57247 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -654,6 +654,18 @@ foreground: Color = .{ .r = 0xFF, .g = 0xFF, .b = 0xFF }, /// Available since: 1.2.0 @"selection-clear-on-typing": bool = true, +/// Whether to clear selected text after copying. This defaults to `false`. +/// +/// When set to `true`, the selection will be automatically cleared after +/// any copy operation that invokes the `copy_to_clipboard` keyboard binding. +/// Importantly, this will not clear the selection if the copy operation +/// was invoked via `copy-on-select`. +/// +/// When set to `false`, the selection remains visible after copying, allowing +/// to see what was copied and potentially perform additional operations +/// on the same selection. +@"selection-clear-on-copy": bool = false, + /// The minimum contrast ratio between the foreground and background colors. /// The contrast ratio is a value between 1 and 21. A value of 1 allows for no /// contrast (e.g. black on black). This value is the contrast ratio as defined