diff options
| author | Gabriel Schneider <[email protected]> | 2026-09-15 12:43:53 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-09-15 17:24:42 -0300 |
| commit | c787d59a987ec601cd7b65399543afe6d37a615d (patch) | |
| tree | b593436d7aa4c37cb0e59eef5412dbb77ae5faad /src/pardes.zig | |
| parent | 8b0bed0427064794725f95cb7b020d7d96956975 (diff) | |
| download | pardes-c787d59a987ec601cd7b65399543afe6d37a615d.tar.gz pardes-c787d59a987ec601cd7b65399543afe6d37a615d.zip | |
Route mouse thumb buttons to jump history
Diffstat (limited to 'src/pardes.zig')
| -rw-r--r-- | src/pardes.zig | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/src/pardes.zig b/src/pardes.zig index 1dbe2e81..efd82474 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -4314,7 +4314,7 @@ test "normal header Enter executes its command rather than searching for it" { pub const Mouse = struct { // sel indexing relies on left/middle/right being 0/1/2 - pub const Button = enum { left, middle, right, wheel_up, wheel_down, wheel_left, wheel_right, none }; + pub const Button = enum { left, middle, right, wheel_up, wheel_down, wheel_left, wheel_right, none, back, forward }; pub const Kind = enum { press, release, motion, drag }; button: Button, kind: Kind, @@ -10747,6 +10747,10 @@ pub const Pardes = struct { } fn handleMouse(p: *Pardes, m: Mouse) void { + if (m.button == .back or m.button == .forward) { + if (m.kind == .press) p.jumpBy(if (m.button == .back) -1 else 1); + return; + } const raw_col = @min(m.col, p.screen_w -| 1); const raw_row = @min(m.row, p.screen_h -| 1); p.pointer_raw_col = raw_col; @@ -10842,7 +10846,7 @@ pub const Pardes = struct { } switch (m.button) { - .none => {}, // hover tracked above; motion has no other meaning + .none, .back, .forward => {}, // hover and navigation handled above .wheel_up, .wheel_down => { if (m.kind != .press) return; // re-arms the drift guard below; vertical always scrolls, so @@ -13948,3 +13952,26 @@ test "jump history terminal rectangle follows output and clears on reflow" { try std.testing.expect(pane.pointerSelection(pane.sel[0]) == null); try std.testing.expectEqual(.none, pane.sel[0].state); } + +test "mouse thumb buttons navigate once without disturbing selection gestures" { + const p = try Pardes.init(std.testing.allocator, .{ .cols = 60, .rows = 12 }); + defer p.deinit(); + const pane = try p.setTestFile("alpha beta\ngamma delta\nepsilon zeta\n"); + pane.setRange(pane.file.?.content, 0, .{ .anchor = 1, .head = 5 }, true); + const selection = pane.primaryRange(pane.file.?.content, 0); + p.njumps = 3; + p.jcur = 2; + for (0..3) |i| p.jumps[i] = .{ .pane = 0, .serial = pane.serial, .line = @intCast(i + 1), .col = 1 }; + p.drag = .{ .select = .{ .id = 0, .button = config.select_button } }; + const drag = p.drag; + p.update(.{ .mouse = .{ .button = .back, .kind = .press, .col = 0, .row = 0 } }); + try std.testing.expectEqual(@as(usize, 1), p.jcur); + for ([_]Mouse.Kind{ .drag, .release, .motion }) |kind| + p.update(.{ .mouse = .{ .button = .back, .kind = kind, .col = 0, .row = 0 } }); + try std.testing.expectEqual(@as(usize, 1), p.jcur); + p.update(.{ .mouse = .{ .button = .forward, .kind = .press, .col = 0, .row = 0 } }); + p.update(.{ .mouse = .{ .button = .forward, .kind = .release, .col = 0, .row = 0 } }); + try std.testing.expectEqual(@as(usize, 2), p.jcur); + try std.testing.expectEqualDeep(selection, pane.primaryRange(pane.file.?.content, 0)); + try std.testing.expectEqualDeep(drag, p.drag); +} |
