From 488e6670c2ba2d7b261bc4deffe2e92276c96db5 Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Fri, 29 Sep 2023 15:56:03 -0500 Subject: [PATCH] selection: only clear when keypress has utf8 Currently, the selection on a surface is cleared on any keypress that generates a control sequence. For applications that enable kitty, this can mean that every keypress clears the current selection thereby making it impossible to copy text, since it will be cleared as soon as Control is pressed. This can be very confusing to terminal users: some applications I can shift+highlight and copy+paste, some I can't - and unless I know the implementation of the application I won't know why...very frustrating. Only clear the selection when there is printable text, otherwise retain the selection. From my testing, this makes text selection feel the same between applications using kitty keyboard and applications that don't. --- src/Surface.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Surface.zig b/src/Surface.zig index 24d60c44b..587e166dc 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -967,9 +967,9 @@ pub fn keyCallback( }, .{ .forever = {} }); try self.io_thread.wakeup.notify(); - // If we have a sequence to emit then we always want to clear the + // If we have printable text to emit then we always want to clear the // selection and scroll to the bottom. - { + if (event.utf8.len > 0) { self.renderer_state.mutex.lock(); defer self.renderer_state.mutex.unlock(); self.setSelection(null);