diff options
Diffstat (limited to 'core')
| -rw-r--r-- | core/Pick.zig | 86 | ||||
| -rw-r--r-- | core/body_layer.zig | 14 |
2 files changed, 85 insertions, 15 deletions
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; |
