From 32961d3e975edd92586ee96a6143b04237025afb Mon Sep 17 00:00:00 2001 From: Justin Su Date: Sun, 28 Jul 2024 19:43:36 -0400 Subject: [PATCH 1/2] Use `Surface.hasSelection()` --- src/Surface.zig | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/Surface.zig b/src/Surface.zig index d138f798f..259c88f14 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -2152,13 +2152,7 @@ pub fn mouseButtonCallback( // Checking for selection requires the renderer state mutex which // sucks but this should be pretty rare of an event so it won't // cause a ton of contention. - const selection = selection: { - self.renderer_state.mutex.lock(); - defer self.renderer_state.mutex.unlock(); - break :selection self.io.terminal.screen.selection != null; - }; - - if (selection) { + if (self.hasSelection()) { const pos = try self.rt_surface.getCursorPos(); try self.cursorPosCallback(pos); return true; From d37c529308f099e4691ff7e614df21150440eb8c Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 31 Jul 2024 19:30:27 -0700 Subject: [PATCH 2/2] update comments --- src/Surface.zig | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Surface.zig b/src/Surface.zig index 259c88f14..e2b5f51a5 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -2145,13 +2145,15 @@ pub fn mouseButtonCallback( // cursorPosCallback will also do a mouse report so we don't need to do any // of the logic below. if (button == .left and action == .press) { + // We could do all the conditionals in one but I find it more + // readable as a human to break this one up. if (mods.shift and self.mouse.left_click_count > 0 and !shift_capture) { - // Checking for selection requires the renderer state mutex which - // sucks but this should be pretty rare of an event so it won't - // cause a ton of contention. + // 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);