diff options
Diffstat (limited to 'core/Pick.zig')
| -rw-r--r-- | core/Pick.zig | 96 |
1 files changed, 82 insertions, 14 deletions
diff --git a/core/Pick.zig b/core/Pick.zig index c05ed084..e3972419 100644 --- a/core/Pick.zig +++ b/core/Pick.zig @@ -209,11 +209,24 @@ pub fn live(p: *const Pardes) ?*Pick { /// 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. +/// again, the pane's own text stays where it was under the band. Code +/// actions' body is their preview from the first, their edit's ghost lines +/// in it (UX DESIGN I1: "a picker and code actions (whose body is the +/// preview) keep D6"): under the head and the band, never under them. 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; + return (pk.previewed or pk.source == .actions) and pane.serial == pk.landing; +} + +/// The live picker whose rows pane `pane`'s body previews, it being its +/// landing pane: what its tag names in place of the preview +/// (tagline.named, UX DESIGN M3); none for a themes or actions picker, +/// whose landing is the asking pane's own text. +pub fn landingOf(p: *const Pardes, pane: *const Pane) ?*const Pick { + const pk = live(p) orelse return null; + if (pk.landing != pane.serial or pk.source == .themes or pk.source == .actions) return null; + return pk; } /// A picker of `source` asked from pane `from`, unrolled in the tag of the @@ -790,9 +803,10 @@ fn rowAt(p: *Pardes, pk: *const Pick, arena: std.mem.Allocator, i: usize) std.me // ---- the tag ---- -/// The head of the landing pane's tag (SPEC §5.3): the key cells, the -/// source's word, the query, the count `cursor/total` and `•marked`; on a -/// second row the other sources' words, under spines from the key cells. +/// The head under the landing pane's tag (SPEC §5.3, UX DESIGN M2): the +/// key cells, the source's word, the query, the count `cursor/total` and +/// `•marked`; on a second row the acts and the other sources' words, under +/// spines from the key cells. pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head { const pk = live(p) orelse return null; const s = &p.view().tag_state; @@ -2155,6 +2169,12 @@ fn tagOf(p: *Pardes, arena: std.mem.Allocator, id: usize) ![]const u8 { return pardes.tagline.tagText(p, arena, p.panes[id].?); } +/// The head under pane `id`'s tag (UX DESIGN M2); none at rest. +fn headOf(p: *Pardes, arena: std.mem.Allocator, id: usize) ![]const u8 { + const h = try TagState.head(p, arena, p.panes[id].?); + return if (h) |made| made.text else ""; +} + fn paneCount(p: *const Pardes) usize { var n: usize = 0; for (p.panes) |slot| n += @intFromBool(slot != null); @@ -2205,9 +2225,9 @@ test "a picker from a held pane unrolls in a reader made for it: its rows in the var frame = std.heap.ArenaAllocator.init(std.testing.allocator); defer frame.deinit(); const a = frame.allocator(); - const tag = try tagOf(p, a, reader); - // Out of rest no path (UX D1): not the previewed file's, not Keep; - // the head starts the tag's text. + // Its tag the owner's word alone (UX DESIGN M3), the head under it. + try std.testing.expect(std.mem.startsWith(u8, try tagOf(p, a, reader), "‹@p")); + const tag = try headOf(p, a, reader); const first = tag[0..std.mem.indexOfScalar(u8, tag, '\n').?]; try std.testing.expect(std.mem.startsWith(u8, first, "␣ f Find pick ") and std.mem.endsWith(u8, first, " 1/1")); try std.testing.expect(std.mem.indexOf(u8, tag, "│ Walk Look Split Newcol Grep Edit Copy Keep Drop | Grep Recent Panes Symbols All Jumplist") != null); @@ -2243,7 +2263,7 @@ test "a picker's act row is one row under the spines, two cells right of the las var frame = std.heap.ArenaAllocator.init(std.testing.allocator); defer frame.deinit(); const a = frame.allocator(); - const tag = try tagOf(p, a, reader); + const tag = try headOf(p, a, reader); var rows = std.mem.splitScalar(u8, tag, '\n'); try std.testing.expect(std.mem.startsWith(u8, rows.next().?, "␣ f Find ")); const acts_row = rows.next().?; @@ -2315,7 +2335,7 @@ test "a picker's band is capped once at open at 40 % of its host pane's rows; th 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); + const under = r.h - (at.tag + at.over); try std.testing.expect(under >= 8); try std.testing.expect(@as(u32, under) * 5 >= @as(u32, r.h) * 3); } @@ -2345,7 +2365,7 @@ test "a picker's keys: Tab marks and moves, M-a all and none, C-SPC refines and try std.testing.expectEqual(@as(u16, 2), s.rows.at); var frame = std.heap.ArenaAllocator.init(std.testing.allocator); defer frame.deinit(); - const refs = try tagOf(p, frame.allocator(), id); + const refs = try headOf(p, frame.allocator(), id); try std.testing.expect(std.mem.indexOf(u8, refs, " Refs ") != null and std.mem.indexOf(u8, refs, " 3/4 •1\n") != null); p.update(.{ .key = .{ .cp = 'a', .alt = true } }); try std.testing.expectEqual(@as(usize, 4), pk.marks.items.len); @@ -2364,7 +2384,7 @@ test "a picker's keys: Tab marks and moves, M-a all and none, C-SPC refines and settle(p); try std.testing.expectEqual(@as(usize, 1), count(p, pk)); _ = frame.reset(.retain_capacity); - const refined = try tagOf(p, frame.allocator(), id); + const refined = try headOf(p, frame.allocator(), id); try std.testing.expect(std.mem.indexOf(u8, refined, " Refs alpha | w ") != null and std.mem.indexOf(u8, refined, " 1/1\n") != null); // Backspace twice: the `w` goes, then the refinement, its query back. p.update(.{ .key = .{ .cp = Key.backspace } }); @@ -3179,8 +3199,8 @@ test "a picker's preview starts under its band: its landing line ⌈visible/3⌉ 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(u16, 0), pane.view.covered); + try std.testing.expectEqual(p.tagTop(pane, r) + at.tag + at.over, 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 } }); @@ -3701,3 +3721,51 @@ test "Find and Grep search the work tree (W8): from a pane deep in a repo Find l try std.testing.expectEqualStrings("/", live(p).?.dir.slice()); p.update(.{ .key = .{ .cp = Key.escape } }); } + +test "a pane made for a picker has no rest: its tag is its owner's word alone, `‹@pN ›`, the head under it; a click on it ends the picker as Esc does, the pane gone and the owner's text as it was (UX DESIGN M3)" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 }); + defer p.deinit(); + p.settings.jumps = .walk; + p.stream.engine = .walk; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + const a_path = try testFile(p, &tmp, "alpha.zig", "const alpha = 1;\n"); + defer p.gpa.free(a_path); + _ = try p.setTestFile("held\n"); + const asker = p.view().active; + Trail.keep(p.panes[asker].?); + p.gpa.free(p.panes[asker].?.file.?.path); + p.panes[asker].?.file.?.path = try std.Io.Dir.path.join(p.gpa, &.{ std.Io.Dir.path.dirname(a_path).?, "held.txt" }); + const npanes = paneCount(p); + open(p, asker, .find, "", "", ""); + const pk = live(p).?; + try std.testing.expect(pk.made); + const reader = p.paneBySerial(pk.landing).?; + settle(p); + p.update(.tick); + try std.testing.expectEqualStrings(a_path, p.panes[reader].?.file.?.path); + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + const a = frame.allocator(); + const owner = try std.fmt.allocPrint(a, "‹@p{d} › ", .{p.panes[asker].?.serial}); + try std.testing.expectEqualStrings(owner, try tagOf(p, a, reader)); + const s = try p.render(a); + const r = p.view().rects[reader]; + var row: std.ArrayList(u8) = .empty; + for (0..2) |y| { + row.clearRetainingCapacity(); + for (s.cells[(@as(usize, r.y) + y) * s.cols + r.x + pardes.TAG_TEXT_INSET ..][0 .. r.w - pardes.TAG_TEXT_INSET]) |cell| try row.appendSlice(a, cell.grapheme()); + // The tag's row, the owner's word; the head's under it. + try std.testing.expect(std.mem.startsWith(u8, row.items, if (y == 0) std.mem.trimEnd(u8, owner, " ") else "␣ f Find ")); + } + // B3 on it: the picker ends, the pane made for it goes, and nothing + // under the press is looked at. + const held = p.panes[asker].?; + const caret = .{ held.body.cur_row, held.body.cur_col }; + p.update(.{ .mouse = .{ .button = .right, .kind = .press, .col = r.x + pardes.TAG_TEXT_INSET + 1, .row = r.y } }); + p.update(.{ .mouse = .{ .button = .right, .kind = .release, .col = r.x + pardes.TAG_TEXT_INSET + 1, .row = r.y } }); + try std.testing.expect(live(p) == null); + try std.testing.expectEqual(npanes, paneCount(p)); + try std.testing.expectEqual(asker, p.view().active); + try std.testing.expectEqual(caret, .{ held.body.cur_row, held.body.cur_col }); +} |
