From d442119d70aaaeaed7c6393be4459b638eec987d Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Thu, 19 Mar 2026 11:12:43 -0700 Subject: [PATCH] unconditional debounce --- src/tui.zig | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/tui.zig b/src/tui.zig index ab96fef..b1175b0 100644 --- a/src/tui.zig +++ b/src/tui.zig @@ -350,11 +350,11 @@ pub const App = struct { fn handleMouse(self: *App, ctx: *vaxis.vxfw.EventContext, mouse: vaxis.Mouse) void { switch (mouse.button) { .wheel_up => { - self.moveBy(-3, true); + self.moveBy(-3); return ctx.consumeAndRedraw(); }, .wheel_down => { - self.moveBy(3, true); + self.moveBy(3); return ctx.consumeAndRedraw(); }, .left => { @@ -563,11 +563,11 @@ pub const App = struct { } }, .select_next => { - self.moveBy(1, false); + self.moveBy(1); return ctx.consumeAndRedraw(); }, .select_prev => { - self.moveBy(-1, false); + self.moveBy(-1); return ctx.consumeAndRedraw(); }, .expand_collapse => { @@ -705,17 +705,14 @@ pub const App = struct { } /// Move cursor/scroll. Positive = down, negative = up. - /// For portfolio and options tabs, moves the row cursor by 1. + /// For portfolio and options tabs, moves the row cursor by 1 with + /// debounce to absorb duplicate events from mouse wheel ticks. /// For other tabs, adjusts scroll_offset by |n|. - /// When from_wheel is true, debounces on cursor tabs to absorb - /// duplicate events that terminals send per physical scroll tick. - fn moveBy(self: *App, n: isize, from_wheel: bool) void { + fn moveBy(self: *App, n: isize) void { if (self.active_tab == .portfolio or self.active_tab == .options) { - if (from_wheel) { - const now = std.time.nanoTimestamp(); - if (now - self.last_wheel_ns < 1 * std.time.ns_per_ms) return; - self.last_wheel_ns = now; - } + const now = std.time.nanoTimestamp(); + if (now - self.last_wheel_ns < 1 * std.time.ns_per_ms) return; + self.last_wheel_ns = now; if (self.active_tab == .portfolio) { stepCursor(&self.cursor, self.portfolio_rows.items.len, n); self.ensureCursorVisible();