diff options
| author | Gabriel Schneider <[email protected]> | 2026-10-21 21:30:19 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-22 10:03:15 -0300 |
| commit | 02841e214442c7a602877883425757b0dab3f924 (patch) | |
| tree | 8e27863c52d128a6fb69d2dbf69e8b5b1df57941 /src/draw.zig | |
| parent | b730ce12667fb75c99b97eafcfc73d7b1f8bdd13 (diff) | |
| download | pardes-02841e214442c7a602877883425757b0dab3f924.tar.gz pardes-02841e214442c7a602877883425757b0dab3f924.zip | |
A click that takes focus glides the cursor once, straight to the click
Diffstat (limited to 'src/draw.zig')
| -rw-r--r-- | src/draw.zig | 47 |
1 files changed, 43 insertions, 4 deletions
diff --git a/src/draw.zig b/src/draw.zig index 84575873..31157b1d 100644 --- a/src/draw.zig +++ b/src/draw.zig @@ -282,15 +282,20 @@ fn glideCursor(p: *Pardes, s: *Surface) void { const seen = frame.unplace(old.place(at)); p.cursor_glide.shift(seen[0] - at[0], seen[1] - at[1]); p.cursor_crossing = true; + p.cursor_held = p.drag == .select; } p.cursor_view = .{ .serial = pane.serial, .line = line, .origin = origin, .inside = inside }; } - p.cursor_glide.aim(box, p.now_ns, motion, snap); + // A click that took focus places the cursor on its release; aimed at + // the pane's old cursor meanwhile, it would glide there first. + if (p.drag != .select) p.cursor_held = false; + if (!p.cursor_held) p.cursor_glide.aim(box, p.now_ns, motion, snap); _ = p.cursor_glide.step(p.now_ns); const moving = p.cursor_glide.moving(); - if (!moving) p.cursor_crossing = false; - // Drawn as the quad while it glides and while its pane moves. - s.chrome.cursor_glide = 2 | @as(u8, @intFromBool(moving or frame.moving())); + if (!moving and !p.cursor_held) p.cursor_crossing = false; + // Drawn as the quad while it glides, while its pane moves and while it + // waits for a click's release. + s.chrome.cursor_glide = 2 | @as(u8, @intFromBool(moving or frame.moving() or p.cursor_held)); // The shell blinks it, from how long ago the last key or click was. if (p.settings.cursor_blink) s.chrome.cursor_idle_ms = @intCast(@min(std.math.maxInt(u32) - 1, (p.now_ns -| p.input_ns) / std.time.ns_per_ms)); @@ -2355,6 +2360,40 @@ test "focus moved to another column glides from where the cursor was drawn" { try std.testing.expect(!p.cursor_glide.moving() and !p.cursor_crossing); } +test "a click that takes focus glides the cursor once, to where it lands on release" { + if (!builtins.capabilities.lift) return error.SkipZigTest; + const p = try Pardes.init(std.testing.allocator, .{ .cols = 120, .rows = 20 }); + defer p.deinit(); + var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer arena.deinit(); + p.settings.motion = .smooth; + try twoColumns(p, &arena); + p.active = 0; + p.advance(3 * std.time.ns_per_s); + _ = arena.reset(.retain_capacity); + const before = try p.render(arena.allocator()); + const was: [2]f32 = .{ before.chrome.cursor_quad[0], before.chrome.cursor_quad[1] }; + // Pressed in the other column: focus moves, the cursor waits. + p.active = 1; + p.drag = .{ .select = .{ .id = 1, .button = config.select_button } }; + for (0..3) |_| { + p.advance(p.now_ns + 100 * std.time.ns_per_ms); + _ = arena.reset(.retain_capacity); + const held = try p.render(arena.allocator()); + try std.testing.expectApproxEqAbs(was[0], held.chrome.cursor_quad[0], 0.01); + try std.testing.expectApproxEqAbs(was[1], held.chrome.cursor_quad[1], 0.01); + } + // Released: one glide, from there to the placed cursor. + p.drag = .none; + _ = arena.reset(.retain_capacity); + _ = try p.render(arena.allocator()); + try std.testing.expect(p.cursor_glide.moving()); + p.advance(p.now_ns + 5 * std.time.ns_per_s); + _ = arena.reset(.retain_capacity); + const landed = try p.render(arena.allocator()); + try std.testing.expectApproxEqAbs(focusedCursorBox(p, landed).?.x, landed.chrome.cursor_quad[0], 0.01); +} + test "focus moving to a pane with no cursor while the cursor glides lets the session go idle" { if (!builtins.capabilities.lift) return error.SkipZigTest; const p = try Pardes.init(std.testing.allocator, .{ .cols = 120, .rows = 20 }); |
