From 3efe88c85c63177af9c1df7a16289efff18d5340 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 27 Jan 2024 19:07:49 -0800 Subject: [PATCH] input: add link highlight always/hover w/ mods --- src/Surface.zig | 2 +- src/config/Config.zig | 2 +- src/input/Link.zig | 9 ++++++--- src/renderer/OpenGL.zig | 1 + src/renderer/link.zig | 9 +++++++-- 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/Surface.zig b/src/Surface.zig index 7b2e21be6..c3e6c592c 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -2289,7 +2289,7 @@ fn linkAtPos( for (self.config.links) |link| { switch (link.highlight) { .always, .hover => {}, - .mods => |v| if (!v.equal(self.mouse.mods)) continue, + .always_mods, .hover_mods => |v| if (!v.equal(self.mouse.mods)) continue, } var it = strmap.searchIterator(link.regex); diff --git a/src/config/Config.zig b/src/config/Config.zig index 3c5c377c3..5e09bf247 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -1437,7 +1437,7 @@ pub fn default(alloc_gpa: Allocator) Allocator.Error!Config { try result.link.links.append(alloc, .{ .regex = url.regex, .action = .{ .open = {} }, - .highlight = .{ .mods = inputpkg.ctrlOrSuper(.{}) }, + .highlight = .{ .hover_mods = inputpkg.ctrlOrSuper(.{}) }, }); return result; diff --git a/src/input/Link.zig b/src/input/Link.zig index bc0aa2265..cdd87ef02 100644 --- a/src/input/Link.zig +++ b/src/input/Link.zig @@ -32,9 +32,12 @@ pub const Highlight = union(enum) { /// Only highlight the link when the mouse is hovering over it. hover: void, - /// Highlight anytime the given mods are pressed, regardless of - /// hover state. - mods: Mods, + /// Highlight anytime the given mods are pressed, either when + /// hovering or always. For always, all links will be highlighted + /// when the mods are pressed regardless of if the mouse is hovering + /// over them. + always_mods: Mods, + hover_mods: Mods, }; /// Returns a new oni.Regex that can be used to match the link. diff --git a/src/renderer/OpenGL.zig b/src/renderer/OpenGL.zig index 643b64bbf..a3e0721ec 100644 --- a/src/renderer/OpenGL.zig +++ b/src/renderer/OpenGL.zig @@ -991,6 +991,7 @@ pub fn rebuildCells( arena_alloc, screen, mouse.point orelse .{}, + mouse.mods, ); // Determine our x/y range for preedit. We don't want to render anything diff --git a/src/renderer/link.zig b/src/renderer/link.zig index 27d396bd2..dda3e726f 100644 --- a/src/renderer/link.zig +++ b/src/renderer/link.zig @@ -96,8 +96,13 @@ pub const Set = struct { // error if any other conditions are added. switch (link.highlight) { .always => {}, - .hover => if (!line.selection().contains(mouse_pt)) continue, - .mods => |v| if (!mouse_mods.equal(v)) continue, + .always_mods => |v| if (!mouse_mods.equal(v)) continue, + inline .hover, .hover_mods => |v, tag| { + if (!line.selection().contains(mouse_pt)) continue; + if (comptime tag == .hover_mods) { + if (!mouse_mods.equal(v)) continue; + } + }, } var it = strmap.searchIterator(link.regex);