From 6d68db3bdc7743a4c51403bfb9ba111f9edd0900 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 27 Sep 2024 14:18:33 -0700 Subject: [PATCH] core: only extend selection on mouse if click interval is exceeded Previously, once we had one click registered, shift+click would always go into selection extend mode. This is not the behavior we want, since we want shift+double/triple click to work in alternate screens. This commit changes the behavior so that we only extend the selection after the multi-click interval has passed. I see a lot of opportunity to improve this whole callback much more but I don't want to risk introducing new bugs since this is a hard to test area, so I'm going to leave it for now. --- src/Surface.zig | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/Surface.zig b/src/Surface.zig index 298b7eabd..e8bbb885f 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -2476,15 +2476,33 @@ pub fn mouseButtonCallback( if (mods.shift and self.mouse.left_click_count > 0 and !shift_capture) - { + extend_selection: { // We split this conditional out on its own because this is the // only one that requires a renderer mutex grab which is VERY // expensive because it could block all our threads. - if (self.hasSelection()) { - const pos = try self.rt_surface.getCursorPos(); - try self.cursorPosCallback(pos, null); - return true; + if (!self.hasSelection()) break :extend_selection; + + // If we are within the interval that the click would register + // an increment then we do not extend the selection. + if (std.time.Instant.now()) |now| { + const since = now.since(self.mouse.left_click_time); + if (since <= self.config.mouse_interval) { + // Click interval very short, we may be increasing + // click counts so we don't extend the selection. + break :extend_selection; + } + } else |err| { + // This is a weird behavior, I think either behavior is actually + // fine. This failure should be exceptionally rare anyways. + // My thinking here is that we can't be sure if we should extend + // the selection or not so we just don't. + log.warn("failed to get time, not extending selection err={}", .{err}); + break :extend_selection; } + + const pos = try self.rt_surface.getCursorPos(); + try self.cursorPosCallback(pos, null); + return true; } }