From 6e78564599271ea27fb36138cb629fa7783b806a Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Fri, 7 Nov 2025 13:37:07 +0100 Subject: [PATCH] feat: add configurable editor idle actions hover and highlight_references closes #370 --- src/config.zig | 7 +++++++ src/tui/editor.zig | 10 ++++++++++ src/tui/tui.zig | 3 +-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/config.zig b/src/config.zig index 9cbb98c..d4056e6 100644 --- a/src/config.zig +++ b/src/config.zig @@ -19,6 +19,8 @@ inline_diagnostics: bool = true, animation_min_lag: usize = 0, //milliseconds animation_max_lag: usize = 50, //milliseconds hover_time_ms: usize = 500, //milliseconds +input_idle_time_ms: usize = 150, //milliseconds +idle_actions: []IdleAction = &.{}, enable_format_on_save: bool = false, restore_last_cursor_position: bool = true, follow_cursor_on_buffer_switch: bool = false, //scroll cursor into view on buffer switch @@ -46,6 +48,11 @@ lsp_output: enum { quiet, verbose } = .quiet, include_files: []const u8 = "", +pub const IdleAction = enum { + hover, + highlight_references, +}; + pub const DigitStyle = enum { ascii, digital, diff --git a/src/tui/editor.zig b/src/tui/editor.zig index b222d79..eef55c5 100644 --- a/src/tui/editor.zig +++ b/src/tui/editor.zig @@ -6376,6 +6376,16 @@ pub const EditorWidget = struct { self.update_hover_timer(.fired); if (self.hover_y >= 0 and self.hover_x >= 0 and self.hover_mouse_event) try self.editor.hover_at_abs(@intCast(self.hover_y), @intCast(self.hover_x)); + } else if (try m.match(.{"input_idle"})) { + for (tui.config().idle_actions) |action| switch (action) { + .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(.{}); + }, + }; } else if (try m.match(.{ "whitespace_mode", tp.extract(&bytes) })) { self.editor.render_whitespace = Editor.from_whitespace_mode(bytes); } else { diff --git a/src/tui/tui.zig b/src/tui/tui.zig index 72bec14..4b7c2de 100644 --- a/src/tui/tui.zig +++ b/src/tui/tui.zig @@ -93,7 +93,6 @@ pub const ClipboardEntry = struct { const keepalive = std.time.us_per_day * 365; // one year const idle_frames = 0; -const input_idle_time_milliseconds = 500; const mouse_idle_time_milliseconds = 3000; const init_delay = 1; // ms @@ -313,7 +312,7 @@ fn update_input_idle_timer(self: *Self) void { _ = self.send_widgets(tp.self_pid(), m) catch {}; } - const delay = std.time.us_per_ms * @as(u64, input_idle_time_milliseconds); + const delay = std.time.us_per_ms * @as(u64, self.config_.input_idle_time_ms); if (self.input_idle_timer) |*t| { t.cancel() catch {}; t.deinit();