diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-25 21:19:37 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-25 21:57:19 -0300 |
| commit | 8e1526a71a74447cbba9f5487ef72d9feccfc0ed (patch) | |
| tree | ca10fd5a4f2d2cffbb3a78299b4d6434395b56bf /core/Pick.zig | |
| parent | 1e8787e0b2eb3eaa4991a5160f6e5c35ba6f132e (diff) | |
| download | pardes-8e1526a71a74447cbba9f5487ef72d9feccfc0ed.tar.gz pardes-8e1526a71a74447cbba9f5487ef72d9feccfc0ed.zip | |
Band, sync, draw, layout, mouse, File: the text stays put under the band: out of rest a tag keeps exactly its rows at rest, and its head's rows past them and the band under it are drawn over the top rows of its body, which never moves, wraps or resizes for them (UX DESIGN I1, on the user's "the other editors when there's new ui on top of the text it doesn't scroll ... I think we should do that, no?"); THE OLD WAY: the band pushed the body down (Pardes.sync grew `tag_rows` by `band_rows` and the head's rows), so every row of the text jumped by the band's height on SPC Down, Help, `:`, the registers, a rolled level of three rows, and back on Esc, while a terminal's and a kind's band was a second path drawn over its body (Band.over, Band.shownRows); THE CHANGE: Band.covered (from the state alone, as takes is) says where a tag out of rest is drawn: its head's rows, the band under them (as many as the pane has; a picker's keeping D6's body under it), and `over`, those past the tag's own rows; sync keeps the tag's rows at rest (the terminal special case is every pane's now) and puts `over` in the pane's view (SessionView.covered) for File.show; draw.render draws the host's tag and band after every body, one path for every pane, the grip's column beside the covered rows on the tag's ground, a caret under them hidden until rest; layout.floorRows borrows for a level, Help, `:` or the registers only the rows its head and band need (a picker and code actions keep D6's 60 % / 6 rows; a terminal's and a kind's size stay their user's); mouse.bandPoint gives a covered row to the band (a head's row over the body: B2/B3 on its word as on the tag's first row, B1 nothing); File.show counts the covered rows like the context rows, so what a state shows (a prompt's current hit, C-r's) is put in the rows left visible, a target already there not moved; TagState's rolled level of a terminal takes its three rows too (over the pty, which keeps its size); `band_rows` goes from Pane and PaneView (the dump: SessionView.covered and Pick.previewed come); W1'S READING (I1 is silent on a landing near a file's top): a picker's preview starts under its band (Pick.previewing: from the first place it shows in its landing pane, the band takes its rows from that body, as before), since Find lands on line 1 and a band over the body's top hid the file's first eleven lines and the landing line; before its first row, and after Esc, the pane's own text is where it was; the GUI's tag rule goes under the head's rows as under the band's (gui.zig paneDecor); TESTS (FIRST, where the old behaviour was asserted, inverted): Band.zig "SPC Down unrolls ... drawn over the top rows of the body, which stays where it was" (was "the body pushed down and never drawn over"), "out of rest the body stays where it was ..." (a rolled level, SPC Down, Help, `:`, the registers and a picker before it previews: every row of text under the rows drawn over it on its screen row at rest, the same first row, size and scroll; Esc leaves the body's rows as at rest), "a level's band covers what it needs ..." (no borrow where head and band fit, exactly head + band where they do not), "a covered row belongs to the band ..." (B1 on a band row over the body moves the level's cursor, on a head's row over it touches no body); Pick.zig "a picker's preview starts under its band ..." (in a reading pane: its text stays before the first row; line 60 at ⌈visible/3⌉ under the band, line 1 on the row right under it; Esc: its own text where it was); Prompt.zig "a search's current hit under C-r's band is put in the rows the band leaves the body ..."; the tests that read `band_rows` read Band.covered; body_layer's D10 test: `g`'s first-line target is under the rolled level's rows now (I2's named cost); GOLDENS re-recorded, every moved row: leader (spc, unmapped: the one line of cmds.txt stays on row 3 under the level's second row instead of row 5, the caret on it hidden), find (nomatch, topbar: a picker with nothing to preview leaves here.txt's line 1 on row 3 under the band instead of row 8; cancel: row 8 no longer listed as changed), ttyhelp (leaderworks: Help's band over the +Help pane's text, whose rows 10-20 keep the previous snap's text instead of moving down seven rows); a user saw the text jump on every SPC Down, Help, `:` with rows, registers Down and a rolled level wider than its tag; core-test 1115/1287 (172 skipped: +3), shell-test 1335/1338 (3 skipped: +3), pane-test 183/184, behaviour-test 280/280 and --replay 20 seeds 0 failures, process-test 0 of 147 failed (3 skipped; 3 goldens re-recorded), term-test 17/17, kitty-test 45/45; the dump fuzz at 40,000 join seeds and 40,000 + 1,779 image seeds 11/11; the soak `replicas -- --clients 5 --rtt 30,80,207`: diverged 0, unequal 0, quiet checks 580/0 480/0 675/0, unlisted stops 0, the corpus 22 of 22 scenes the same, no leak; load 1.2 to 10.9
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE
Diffstat (limited to 'core/Pick.zig')
| -rw-r--r-- | core/Pick.zig | 92 |
1 files changed, 86 insertions, 6 deletions
diff --git a/core/Pick.zig b/core/Pick.zig index b76020ca..12062894 100644 --- a/core/Pick.zig +++ b/core/Pick.zig @@ -125,6 +125,9 @@ aside_top: usize = 0, /// again on the frame after the cursor moves to another, never on the key /// that moved it, and on the frame a row first comes under it. shown: u32 = no_row, +/// A place shown in its landing pane's body since it unrolled: the band +/// takes its rows from that body (`previewing`). +previewed: bool = false, /// The preview on (M-p). previews: bool = true, /// Marked rows (Tab), by what each is (`idOf`), in order. @@ -186,6 +189,18 @@ pub fn live(p: *const Pardes) ?*Pick { return if (pk.unrolled) pk else null; } +/// Whether pane `id`'s body is the live picker's preview: a place shown in +/// it. Its band then takes its rows from the body, which starts under the +/// band (Pardes.sync), as a file's first lines could not be put under it +/// otherwise (UX DESIGN I1's "a picker's landing line at a third below +/// the band" for Find's line 1: W1's reading); before that, and at rest +/// again, the pane's own text stays where it was under the band. +pub fn previewing(p: *const Pardes, id: usize) bool { + const pk = live(p) orelse return false; + const pane = p.panes[id] orelse return false; + return pk.previewed and pane.serial == pk.landing; +} + /// A picker of `source` asked from pane `from`, unrolled in the tag of the /// pane its Enter will land in (SPEC §3.5), its field `query`. `rows` are /// a list's (`source` `list`, titled `word`). @@ -277,6 +292,7 @@ fn unroll(p: *Pardes, pk: *Pick, query: []const u8) void { s.rows = .{ .at = @intCast(@min(pk.at, std.math.maxInt(u16))) }; pk.unrolled = true; pk.shown = no_row; + pk.previewed = false; // The whole window previews a theme. if (pk.source == .themes) s.previewing = .full; if (p.paneBySerial(pk.landing)) |id| { @@ -852,6 +868,13 @@ fn preview(p: *Pardes, pk: *Pick) void { pane.places.clear(p.gpa); } pane.hscroll = 0; + pk.previewed = true; + p.sync(); + } + // The body under the band from the first place it shows (previewing): + // laid out again before the place is put in its rows. + if (!pk.previewed) { + pk.previewed = true; p.sync(); } const keyboard = p.view().active; @@ -1802,7 +1825,7 @@ test "a picker from a held pane unrolls in a reader made for it: its rows in the _ = try p.render(a); const r = p.view().rects[reader]; try std.testing.expectEqualStrings("^", p.surface.at(r.x, r.y).grapheme()); - try std.testing.expect(p.panes[reader].?.band_rows >= 1); + try std.testing.expect(Band.covered(p, p.panes[reader].?, reader).band >= 1); // Esc: the reader made for it goes, the asker as it was. p.update(.{ .key = .{ .cp = Key.escape } }); try std.testing.expectEqual(npanes, paneCount(p)); @@ -1859,14 +1882,14 @@ test "a picker's band is sized from its list at open, 4 rows at least, and typin settle(p); const reader = p.paneBySerial(live(p).?.landing).?; p.sync(); - const rows = p.panes[reader].?.band_rows; + const rows = Band.covered(p, p.panes[reader].?, reader).band; // One or two files listed: four rows, ground under them. try std.testing.expectEqual(@as(u16, 4), rows); for ("zzq") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } }); settle(p); p.sync(); try std.testing.expectEqual(@as(usize, 0), count(p, live(p).?)); - try std.testing.expectEqual(rows, p.panes[reader].?.band_rows); + try std.testing.expectEqual(rows, Band.covered(p, p.panes[reader].?, reader).band); } test "a picker's band is capped once at open at 40 % of its host pane's rows; the host borrows from its column for a body of 60 % before the band gives way: a Grep from a held pane at 100x30 previews 8 rows at least" { @@ -1896,9 +1919,13 @@ test "a picker's band is capped once at open at 40 % of its host pane's rows; th p.sync(); const pane = p.panes[reader].?; const r = p.view().rects[reader]; - try std.testing.expectEqual(@min(Band.Cursor.shown, at_open * 2 / 5), pane.band_rows); - try std.testing.expect(r.h - pane.tag_rows >= 8); - try std.testing.expect(@as(u32, r.h - pane.tag_rows) * 5 >= @as(u32, r.h) * 3); + const at = Band.covered(p, pane, reader); + try std.testing.expectEqual(@min(Band.Cursor.shown, at_open * 2 / 5), at.band); + // The rows under the band, the preview's (no row previewed yet: the + // band over the reader's text, UX DESIGN I1). + const under = r.h - @max(pane.tag_rows, at.text + at.band); + try std.testing.expect(under >= 8); + try std.testing.expect(@as(u32, under) * 5 >= @as(u32, r.h) * 3); } test "a picker's keys: Tab marks and moves, M-a all and none, C-SPC refines and Backspace undoes it, M-h switches source keeping the query" { @@ -2620,3 +2647,56 @@ test "Backspace on a Messages picker's empty field goes back to the level it was p.sync(); _ = try p.render(frame.allocator()); } + +test "a picker's preview starts under its band: its landing line ⌈visible/3⌉ rows below the band's last row, a file's line 1 on the row right under it; before its first row and after Esc the pane's own text where it was at rest (UX DESIGN I1, W1's reading)" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 }); + defer p.deinit(); + p.settings.jumps = .walk; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + var text: std.ArrayList(u8) = .empty; + defer text.deinit(std.testing.allocator); + for (1..121) |i| try text.print(std.testing.allocator, "line {d} of the file\n", .{i}); + const path = try testFile(p, &tmp, "long.zig", text.items); + defer p.gpa.free(path); + var own: std.ArrayList(u8) = .empty; + defer own.deinit(std.testing.allocator); + for (1..81) |i| try own.print(std.testing.allocator, "own {d}\n", .{i}); + const pane = try p.setTestFile(own.items); + const id = p.view().active; + pane.focus = .body; + for ("75j") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } }); + p.sync(); + const r = p.view().rects[id]; + const rest = .{ pane.tag_rows, pane.rows, pane.file.?.scroll, p.bodyTop(pane, r) }; + try std.testing.expect(rest[2] > 0); + const rows = try std.fmt.allocPrint(std.testing.allocator, "{s}:60:1 line 60 of the file\n{s}:1:1 line 1 of the file\n", .{ path, path }); + defer std.testing.allocator.free(rows); + open(p, id, .list, "Refs", "", rows); + p.sync(); + // In the pane itself (it reads), no row shown yet: its text stays. + try std.testing.expectEqual(id, p.paneBySerial(live(p).?.landing).?); + try std.testing.expect(!previewing(p, id)); + try std.testing.expectEqual(rest, .{ pane.tag_rows, pane.rows, pane.file.?.scroll, p.bodyTop(pane, r) }); + try std.testing.expect(Band.covered(p, pane, id).over > 0); + // The first row shown: the body under the band, line 60 a third of + // its rows down. + p.update(.tick); + try std.testing.expect(previewing(p, id)); + try std.testing.expectEqualStrings(path, pane.file.?.path); + const at = Band.covered(p, pane, id); + try std.testing.expectEqual(@as(u16, 0), at.over); + try std.testing.expectEqual(p.tagTop(pane, r) + at.text + at.band, p.bodyTop(pane, r)); + try std.testing.expectEqual(@as(usize, 59 - (pane.rows + 2) / 3), pane.file.?.scroll); + // Line 1: on the row right under the band. + p.update(.{ .key = .{ .cp = Key.down } }); + p.update(.tick); + try std.testing.expectEqual(@as(usize, 0), pane.file.?.scroll); + try std.testing.expectEqual(@as(i32, 0), pane.body.cur_row); + // Esc: the pane's own text, where it was at rest. + p.update(.{ .key = .{ .cp = Key.escape } }); + p.sync(); + try std.testing.expect(live(p) == null); + try std.testing.expectEqual(rest, .{ pane.tag_rows, pane.rows, pane.file.?.scroll, p.bodyTop(pane, r) }); + try std.testing.expect(std.mem.startsWith(u8, pane.file.?.content, "own 1\n")); +} |
