From dfcca170eff58eee462526563d9012219c9efde0 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Wed, 14 Jan 2026 12:58:24 +0100 Subject: [PATCH] fix: highlight_references idle_action should cancel and not flicker --- src/tui/editor.zig | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/tui/editor.zig b/src/tui/editor.zig index 34fa63b..7472990 100644 --- a/src/tui/editor.zig +++ b/src/tui/editor.zig @@ -5672,7 +5672,15 @@ pub const Editor = struct { (self.matches.addOne(self.allocator) catch return).* = match; } - fn find_selection_match(self: *const Self, sel: Selection) ?*Match { + fn match_at_cursor(self: *const Self, cursor: Cursor) ?*Match { + for (self.matches.items) |*match_| if (match_.*) |*match| { + if (cursor.within(match.to_selection()) or cursor.eql(match.end)) + return match; + }; + return null; + } + + pub fn find_selection_match(self: *const Self, sel: Selection) ?*Match { for (self.matches.items) |*match_| if (match_.*) |*match| { if (match.to_selection().eql(sel)) return match; @@ -6931,10 +6939,7 @@ pub const EditorWidget = struct { .hover => { try self.editor.hover(.{}); }, - .highlight_references => { - if (self.editor.cursels.items.len == 1 and self.editor.get_primary().selection == null) - try self.editor.highlight_references(.{}); - }, + .highlight_references => self.idle_highlight_references(), }; } else if (try m.match(.{ "whitespace_mode", tp.extract(&whitespace_mode) })) { self.editor.render_whitespace = whitespace_mode; @@ -6944,6 +6949,22 @@ pub const EditorWidget = struct { return true; } + fn idle_highlight_references(self: *Self) void { + const primary = self.editor.get_primary(); + switch (self.editor.match_type) { + .find, .auto_find => return, + .highlight_references => { + if (self.editor.match_at_cursor(primary.cursor) == null) { + self.editor.cancel_all_matches(); + tui.need_render(); + } + }, + .none => {}, + } + if (self.editor.cursels.items.len == 1 and primary.selection == null) + self.editor.highlight_references(.{}) catch return; + } + fn update_hover_timer(self: *Self, event: enum { init, fired, cancel }) void { if (self.hover_timer) |*t| { if (event != .fired) t.cancel() catch {};