fix: highlight_references idle_action should cancel and not flicker

This commit is contained in:
CJ van den Berg 2026-01-14 12:58:24 +01:00
parent 5362966a59
commit dfcca170ef
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -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 {};