core: handle URL clicking properly with shift-escaping mouse events

This commit is contained in:
Mitchell Hashimoto
2023-11-29 15:15:16 -08:00
parent 056e96748a
commit 0938a0d638

View File

@ -1228,6 +1228,10 @@ pub fn keyCallback(
self.hideMouse(); self.hideMouse();
} }
// We always update our mouse mods here too because otherwise we only
// get mods when a button is pressed.
self.mouse.mods = event.mods;
// When we are in the middle of a mouse event and we press shift, // When we are in the middle of a mouse event and we press shift,
// we change the mouse to a text shape so that selection appears // we change the mouse to a text shape so that selection appears
// possible. // possible.
@ -1876,7 +1880,7 @@ pub fn mouseButtonCallback(
// Handle link clicking. We want to do this before we do mouse // Handle link clicking. We want to do this before we do mouse
// reporting or any other mouse handling because a successfully // reporting or any other mouse handling because a successfully
// clicked link will swallow the event. // clicked link will swallow the event.
if (button == .left and action == .release) { if (button == .left and action == .release and self.mouse.over_link) {
const pos = try self.rt_surface.getCursorPos(); const pos = try self.rt_surface.getCursorPos();
if (self.processLinks(pos)) |processed| { if (self.processLinks(pos)) |processed| {
if (processed) return; if (processed) return;
@ -2085,6 +2089,12 @@ pub fn cursorPosCallback(
// The mouse position in the viewport // The mouse position in the viewport
const pos_vp = self.posToViewport(pos.x, pos.y); const pos_vp = self.posToViewport(pos.x, pos.y);
// We always reset the over link status because it will be reprocessed
// below. But we need the old value to know if we need to undo mouse
// shape changes.
const over_link = self.mouse.over_link;
self.mouse.over_link = false;
// We are reading/writing state for the remainder // We are reading/writing state for the remainder
self.renderer_state.mutex.lock(); self.renderer_state.mutex.lock();
defer self.renderer_state.mutex.unlock(); defer self.renderer_state.mutex.unlock();
@ -2106,7 +2116,6 @@ pub fn cursorPosCallback(
if (self.io.terminal.flags.mouse_event != .none) report: { if (self.io.terminal.flags.mouse_event != .none) report: {
// Shift overrides mouse "grabbing" in the window, taken from Kitty. // Shift overrides mouse "grabbing" in the window, taken from Kitty.
if (self.mouse.mods.shift and if (self.mouse.mods.shift and
self.mouse.click_state[@intFromEnum(input.MouseButton.left)] == .press and
!self.mouseShiftCapture(false)) break :report; !self.mouseShiftCapture(false)) break :report;
// We use the first mouse button we find pressed in order to report // We use the first mouse button we find pressed in order to report
@ -2162,8 +2171,7 @@ pub fn cursorPosCallback(
self.mouse.over_link = true; self.mouse.over_link = true;
try self.rt_surface.setMouseShape(.pointer); try self.rt_surface.setMouseShape(.pointer);
try self.queueRender(); try self.queueRender();
} else if (self.mouse.over_link) { } else if (over_link) {
self.mouse.over_link = false;
try self.rt_surface.setMouseShape(self.io.terminal.mouse_shape); try self.rt_surface.setMouseShape(self.io.terminal.mouse_shape);
try self.queueRender(); try self.queueRender();
} }