From c496956f395783085a249a4b1063abb577e4c3c2 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 26 Nov 2026 13:07:24 -0300 Subject: Pick, body_layer: a picker's landing-line mark (`▸` in the gutter and the hit ground, UX D7) is drawn where Enter lands, the row's own place, never at the preview's caret, which a click in the preview moves while the picker waits (W9's small fault, found in its S-kit shoot: after B1 in the preview pane the mark followed the clicked line while ⏎ landed on the row's place); THE CAUSE: Pick.landingLine answered `pane.body.cur_row`, the caret's line, which `preview` puts on the row's place and which nothing else moved while a picker held the keyboard; since UX DESIGN O2 (W9's olkkpllo) B1 in the preview gives that pane the keyboard and leaves the picker up and waiting, so the caret goes where the click is, and the mark with it, while `land` opens the row's place (look.open with the row's `at`); paintLandingSpan read the caret's column the same way (the Grep match it lights on the landing line); THE FIX: landingLine answers the row's place as `preview` and look.focusPaneLine put the caret there, its line (past the `Changes` layer's lines, a place past the file's end its first line) and its byte in the line, and paintLandingSpan takes that byte; RUN (TEST FIRST): Pick.zig "the landing line's mark shows where Enter lands, the row's own place, not the preview's caret: ..." opens a list from a held pane, its row long.zig:40:6 previewed in the made reader, B1 on line 43 of the preview (the caret there, the picker waiting) and asks `▸` and the hit ground on line 40's row and neither on the clicked one, then B1 on the head and Enter landing on line 40: fails on the merge at Pick.zig:3998 (the mark on the caret's row), passes now; the three tests that read landingLine read its `.line`; a user hit it with every click in a picker's preview pane since part O; GATES (Debug tui): core-test 1171/1346 (175 skipped: the merge's 1163/1338 + this test + the importer's 7 counted again after a cache wipe); load 1.9 to 2.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE --- core/Pick.zig | 86 ++++++++++++++++++++++++++++++++++++++++++++++++----- core/body_layer.zig | 14 ++++----- 2 files changed, 85 insertions(+), 15 deletions(-) (limited to 'core') diff --git a/core/Pick.zig b/core/Pick.zig index 6899f607..39202fb9 100644 --- a/core/Pick.zig +++ b/core/Pick.zig @@ -956,10 +956,13 @@ fn listedStep(p: *Pardes, pk: *const Pick, arena: std.mem.Allocator) !Band.Step // ---- the preview ---- -/// The line (from 0) pane `pane`'s body lands the live picker's cursor row -/// on, while it is that picker's landing pane previewing that row's file -/// (UX D7: drawn on the hit ground, body_layer.zig); null else. -pub fn landingLine(p: *Pardes, arena: std.mem.Allocator, pane: *const Pane) ?usize { +/// The line (from 0) and the byte in it that pane `pane`'s body lands the +/// live picker's cursor row on, while it is that picker's landing pane +/// previewing that row's file (UX D7: drawn on the hit ground, +/// body_layer.zig); null else. The row's own place, where Enter lands +/// (`land`) and `preview` put the caret: never the caret, which a click in +/// the preview moves while the picker waits (UX DESIGN O2). +pub fn landingLine(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) ?struct { line: usize, col: usize } { const pk = live(p) orelse return null; // A theme or an action lands nowhere: the window wearing it, its // edit on the Changes grounds are their previews. @@ -971,9 +974,13 @@ pub fn landingLine(p: *Pardes, arena: std.mem.Allocator, pane: *const Pane) ?usi .place => |t| t, else => return null, }; - const f = pane.file orelse return null; + const f = if (pane.file) |*file| file else return null; if (!std.mem.eql(u8, f.path, place.path)) return null; - return @intCast(@max(0, pane.body.cur_row)); + // As `preview` and look.focusPaneLine put the caret: a place past the + // file's end on its first line; past the `Changes` layer's lines. + if (place.at.line == 0 or place.at.line > File.nlines(p.gpa, f)) return .{ .line = 0, .col = 0 }; + const line = File.bufferRow(f, place.at.line - 1); + return .{ .line = line, .col = @min(place.at.col -| 1, File.sourceLine(pane, @intCast(line)).len) }; } /// The notice row's sentence while a picker previews (UX D7), written to @@ -3104,7 +3111,7 @@ test "a picker previews the row under its cursor from the frame its rows come, w settle(p); try std.testing.expectEqual(@as(usize, 1), count(p, live(p).?)); try std.testing.expectEqualStrings(a_path, p.panes[reader].?.file.?.path); - try std.testing.expectEqual(@as(?usize, 0), landingLine(p, frame.allocator(), p.panes[reader].?)); + try std.testing.expectEqual(@as(usize, 0), landingLine(p, frame.allocator(), p.panes[reader].?).?.line); p.update(.{ .key = .{ .cp = Key.escape } }); // Grep: its lines come once the typing pauses, frames with none before. open(p, asker, .grep, "", "", ""); @@ -3117,7 +3124,7 @@ test "a picker previews the row under its cursor from the frame its rows come, w settle(p); try std.testing.expectEqual(@as(usize, 1), count(p, live(p).?)); try std.testing.expectEqualStrings(a_path, p.panes[greader].?.file.?.path); - try std.testing.expectEqual(@as(?usize, 1), landingLine(p, frame.allocator(), p.panes[greader].?)); + try std.testing.expectEqual(@as(usize, 1), landingLine(p, frame.allocator(), p.panes[greader].?).?.line); } test "Backspace on a Messages picker's empty field goes back to the level it was run from, SPC h, unrolled and drawn: its keys are its level's, as every other picker's are" { @@ -3948,3 +3955,66 @@ test "a picker from a held pane with a reader hangs under the held pane's tag an p.update(.{ .key = .{ .cp = Key.escape } }); try std.testing.expectEqualStrings(a_path, p.panes[reader].?.file.?.path); } + +test "the landing line's mark shows where Enter lands, the row's own place, not the preview's caret: B1 on another line of the preview moves the caret there and the picker waits, the mark and its ground stay on the row's line; Enter from the field lands there (UX DESIGN O2, D7)" { + 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..81) |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); + _ = try p.setTestFile("held\n"); + const asker = p.view().active; + Trail.keep(p.panes[asker].?); + const rows = try std.fmt.allocPrint(std.testing.allocator, "{s}:40:6 line 40 of the file\n", .{path}); + defer std.testing.allocator.free(rows); + open(p, asker, .list, "Refs", "", rows); + const pk = live(p).?; + const reader = p.paneBySerial(pk.landing).?; + p.update(.tick); + const pane = p.panes[reader].?; + try std.testing.expectEqual(@as(i32, 39), pane.body.cur_row); + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + const Shown = struct { + // The screen row of the body's line `line` (from 0). + fn row(q: *Pardes, t: *Pane, line: usize) u16 { + const r = q.view().rects[panes.paneIdOf(q, t).?]; + for (0..t.rows) |at| if (t.wrapAt(q.settings.tab, @intCast(at)).line == line) return q.bodyTop(t, r) + @as(u16, @intCast(at)); + unreachable; + } + }; + // B1 three lines under the landing line: the caret there, the + // keyboard in the reader, the picker waiting. + const r = p.view().rects[reader]; + const tx = r.x + config.GUTTER; + const gutter = File.gutterWidth(pane); + const clicked = Shown.row(p, pane, 42); + for ([_]pardes.Mouse.Kind{ .press, .release }) |kind| p.update(.{ .mouse = .{ .button = .left, .kind = kind, .col = tx + gutter + 2, .row = clicked } }); + try std.testing.expect(live(p) == pk and p.view().tag_state.waits and p.view().active == reader); + try std.testing.expectEqual(@as(i32, 42), pane.body.cur_row); + // The mark and the hit ground on line 40's row, where Enter lands; + // none on the caret's. + const s = try p.render(frame.allocator()); + const c = p.chrome(); + const landing = Shown.row(p, pane, 39); + try std.testing.expectEqualStrings("▸", s.at(tx + gutter - 1, landing).grapheme()); + try std.testing.expectEqual(pardes.Color{ .rgb = c.hit }, s.at(tx + gutter + 2, landing).style.bg); + try std.testing.expect(!std.mem.eql(u8, "▸", s.at(tx + gutter - 1, clicked).grapheme())); + try std.testing.expect(!std.meta.eql(pardes.Color{ .rgb = c.hit }, s.at(tx + gutter + 2, clicked).style.bg)); + // B1 on the head gives the field the keyboard back; Enter lands on + // line 40, where the mark was. + const at = Band.covered(p, p.panes[asker].?, asker); + const ar = p.view().rects[asker]; + for ([_]pardes.Mouse.Kind{ .press, .release }) |kind| p.update(.{ .mouse = .{ .button = .left, .kind = kind, .col = ar.x + pardes.TAG_TEXT_INSET + 8, .row = ar.y + at.tag } }); + try std.testing.expect(!p.view().tag_state.waits and p.view().active == asker); + p.update(.{ .key = .{ .cp = Key.enter } }); + try std.testing.expect(live(p) == null); + const landed = p.panes[p.view().active].?; + try std.testing.expectEqualStrings(path, landed.file.?.path); + try std.testing.expectEqual(@as(i32, 39), landed.body.cur_row); +} diff --git a/core/body_layer.zig b/core/body_layer.zig index 46a98760..8c156a84 100644 --- a/core/body_layer.zig +++ b/core/body_layer.zig @@ -332,9 +332,9 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane drawWrapMarkers(p, s, pane, r, tx, tw, body_h, pane_bg); // A picker's landing line under the places it lights (UX D7). const landing = pardes.Pick.landingLine(p, arena, pane); - if (landing) |line| paintLanding(p, s, pane, r, tx, tw, body_h, line); + if (landing) |at| paintLanding(p, s, pane, r, tx, tw, body_h, at.line); pane.places.paint(p, s, pane, r, body_h); - if (landing) |line| paintLandingSpan(p, s, pane, r, f, line); + if (landing) |at| paintLandingSpan(p, s, pane, r, f, at.line, at.col); pardes.Prompt.paintGutter(p, s, pane, r, body_h); panes.Query.paint(p, s, pane, r, body_h); } else if (pane.isTerminal()) { @@ -688,14 +688,14 @@ fn paintLanding(p: *Pardes, s: *Surface, pane: *Pane, r: Rect, tx: u16, tw: u16, } } -/// The landing line's matched span (a Grep's match at the row's column) as -/// the current hit, solid in the hue with the page's ink, over the places -/// lit on it (UX D7, R8). -fn paintLandingSpan(p: *Pardes, s: *Surface, pane: *Pane, r: Rect, f: *panes.File.State, line: usize) void { +/// The landing line's matched span (a Grep's match at the row's column, +/// byte `col` of the line) as the current hit, solid in the hue with the +/// page's ink, over the places lit on it (UX D7, R8). +fn paintLandingSpan(p: *Pardes, s: *Surface, pane: *Pane, r: Rect, f: *panes.File.State, line: usize, col: usize) void { if (!pane.places.shows(pane)) return; const hits = pane.places.hits.items; const ls = File.lineStart(p.gpa, f, line); - const caret = ls + @as(usize, @intCast(@max(0, pane.body.cur_col))); + const caret = ls + col; var i = panes.Places.firstFrom(hits, ls); while (i < hits.len and hits[i].start <= caret) : (i += 1) { if (hits[i].end <= caret) continue; -- cgit v1.3