diff options
Diffstat (limited to 'src/draw.zig')
| -rw-r--r-- | src/draw.zig | 73 |
1 files changed, 62 insertions, 11 deletions
diff --git a/src/draw.zig b/src/draw.zig index 265e07c1..e3ab9f2a 100644 --- a/src/draw.zig +++ b/src/draw.zig @@ -239,8 +239,8 @@ fn glideCursor(p: *Pardes, s: *Surface) void { }; const motion = animation.Motion.of(p.settings.motion); // The thin insert-mode caret glides as the block does (a jump smears - // and bows, a step eases); only a scroll, below, lands it. - var snap = false; + // and bows, a step eases); a scroll moves it rigidly, below. + var how: animation.CursorGlide.How = .ease; var frame: PaneFrame = .{}; // In a column's or the workspace's tag the cursor is not the pane's, // and does not move with it. @@ -259,14 +259,14 @@ fn glideCursor(p: *Pardes, s: *Surface) void { // The pane moved in the layout: the springs move with it (its // own cursor's; one in a column's tag stays). if (inside) p.cursor_glide.shift(origin[0] - view.origin[0], origin[1] - view.origin[1]); - // Scrolled (a file's view, a terminal's output): the quad moves - // with the text and lands, never gliding against text that - // jumped (every Enter at a prompt scrolls one and moves the - // other). - if (inside and line != view.line) { - p.cursor_glide.shift(0, @floatFromInt(view.line - line)); - snap = true; - } + // Scrolled (a file's view, a terminal's output): the caret is its + // own body, drawn from its own springs only, never from the text's + // glide. Its mark is where it will be once the view settles (its + // cell now: the core's view is that one), so a page that keeps its + // row leaves it still, and a scroll that carries its line moves + // it there whole, at the view's pace, not as a jump's smear. A + // terminal's output scrolls it with no glide: it lands with it. + if (inside and line != view.line) how = if (pane.isTerminal()) .land else .rigid; } else if (view.serial != 0 and p.cursor_glide.placed) { // Focus moved (to another pane, or between a pane and a // column's or the workspace's tag): the glide starts where the @@ -290,7 +290,7 @@ fn glideCursor(p: *Pardes, s: *Surface) void { // 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); + if (!p.cursor_held) p.cursor_glide.aim(box, p.now_ns, motion, how); _ = p.cursor_glide.step(p.now_ns); const moving = p.cursor_glide.moving(); if (!moving and !p.cursor_held) p.cursor_crossing = false; @@ -1971,6 +1971,57 @@ test "each Motion flavour reaches the lift as its own trajectory" { try std.testing.expect(peaks[2] <= 1.001 and peaks[3] > 1.25 and peaks[4] > peaks[3]); } +test "the caret is its own body: a page leaves it still under the moving text, a wheel scroll moves it whole to its line's new row" { + if (!builtins.capabilities.lift) return error.SkipZigTest; + const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 30 }); + defer p.deinit(); + var text: std.ArrayList(u8) = .empty; + defer text.deinit(std.testing.allocator); + for (0..400) |i| try text.print(std.testing.allocator, "line {d}\n", .{i}); + const pane = try p.setTestFile(text.items); + p.settings.cursor_blink = false; + var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer arena.deinit(); + var now: u64 = std.time.ns_per_s; + p.advance(now); + // Mid-file, where a half page keeps the caret's row. + for ("200G") |ch| p.update(.{ .key = .{ .cp = ch, .text = &.{ch} } }); + _ = try p.render(arena.allocator()); + now += std.time.ns_per_s; + p.advance(now); + _ = arena.reset(.retain_capacity); + _ = try p.render(arena.allocator()); + // Ctrl-d: the caret moves with the view and keeps its screen row: it + // does not ride the glide, and it does not move. + const row_before = (try p.render(arena.allocator())).cursor.?.y; + p.update(.{ .key = .{ .cp = 'd', .ctrl = true } }); + now += 16 * std.time.ns_per_ms; + p.advance(now); + _ = arena.reset(.retain_capacity); + var s = try p.render(arena.allocator()); + try std.testing.expect(pane.file.?.scroll > 0); + try std.testing.expectEqual(row_before, s.cursor.?.y); + try std.testing.expectEqual(@as(u8, 0), s.chrome.cursor_glide & 1); + try std.testing.expectEqual(@as(f32, @floatFromInt(row_before)), s.chrome.cursor_quad[1]); + // The view scrolled with the caret on its line: it heads for the + // line's new row whole (every corner the same way), and lands on it. + pane.scrollBy(-3); + now += 16 * std.time.ns_per_ms; + p.advance(now); + _ = arena.reset(.retain_capacity); + s = try p.render(arena.allocator()); + const mark: f32 = @floatFromInt(s.cursor.?.y); + try std.testing.expect(s.chrome.cursor_glide & 1 != 0 and s.chrome.cursor_quad[1] < mark); + try std.testing.expectApproxEqAbs(s.chrome.cursor_quad[3] - s.chrome.cursor_quad[1], s.chrome.cursor_quad[5] - s.chrome.cursor_quad[7], 1e-4); + while (p.continuous()) { + now += 7 * std.time.ns_per_ms; + p.advance(now); + _ = arena.reset(.retain_capacity); + s = try p.render(arena.allocator()); + } + try std.testing.expectEqual(mark, s.chrome.cursor_quad[1]); +} + test "the focused cursor glides a jump, eases a step, the thin caret too, and is exact at rest" { if (!builtins.capabilities.lift) return error.SkipZigTest; const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 30 }); |
