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.
This commit is contained in:
Mitchell Hashimoto
2024-09-27 14:18:33 -07:00
parent e5b532f119
commit 6d68db3bdc

View File

@ -2476,15 +2476,33 @@ pub fn mouseButtonCallback(
if (mods.shift and if (mods.shift and
self.mouse.left_click_count > 0 and self.mouse.left_click_count > 0 and
!shift_capture) !shift_capture)
{ extend_selection: {
// We split this conditional out on its own because this is the // We split this conditional out on its own because this is the
// only one that requires a renderer mutex grab which is VERY // only one that requires a renderer mutex grab which is VERY
// expensive because it could block all our threads. // expensive because it could block all our threads.
if (self.hasSelection()) { if (!self.hasSelection()) break :extend_selection;
const pos = try self.rt_surface.getCursorPos();
try self.cursorPosCallback(pos, null); // If we are within the interval that the click would register
return true; // 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;
} }
} }