unconditional debounce
This commit is contained in:
parent
43ab8d1957
commit
d442119d70
1 changed files with 10 additions and 13 deletions
23
src/tui.zig
23
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();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue