diff options
| -rw-r--r-- | core/Pick.zig | 48 | ||||
| -rw-r--r-- | test/snapshots/fsearch.golden | 57 |
2 files changed, 71 insertions, 34 deletions
diff --git a/core/Pick.zig b/core/Pick.zig index c5b639cd..fe7454b3 100644 --- a/core/Pick.zig +++ b/core/Pick.zig @@ -94,6 +94,10 @@ owner: u32 = 0, landing: u32 = 0, /// The landing pane was made for it: Esc takes it away. made: bool = false, +/// Its band's rows at most: 40 % of its host pane's rows at open (UX D6), +/// fixed: the layout that borrows the host's body from its column reads +/// it, and a pane laid out again changes it no more than typing does. +cap: u16 = 0, /// Unrolled in a view's tag now. unrolled: bool = false, names: Names = .{}, @@ -192,6 +196,7 @@ pub fn open(p: *Pardes, from: usize, source: Source, word: []const u8, query: [] pk.dir.set(Pardes.paneDir(asker)); pk.rows = p.gpa.dupe(u8, rows) catch |err| return p.reportError(.at(from), "pick", err); hostIn(p, pk, from) catch |err| return p.reportError(.at(from), "pick", err); + if (p.paneBySerial(pk.landing)) |host| pk.cap = p.view().rects[host].h * 2 / 5; unroll(p, pk, query); start(p, pk); filter(p, pk); @@ -669,16 +674,13 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head { /// The band's rows (UX D6): as many as the list will show, from what the /// source has (not what the query keeps: typing never moves the body), -/// four at least, eleven at most, and 40 % of the host's column at most -/// (its panes' rows, which a borrow moves between them, never changes). +/// four at least, eleven at most, and its `cap` at most (the host pane's +/// 40 % at open: the layout asks this while it lays the column out, when +/// no pane has its rows yet). pub fn bandRows(p: *const Pardes) u16 { const pk = live(p) orelse return 0; const have = if (!fuzzy(pk)) Band.Cursor.shown else pk.names.cands.items.len; - const v = p.view(); - const at = @import("layout.zig").findPane(p, TagState.hostOf(p) orelse return 0) orelse return 0; - var column: usize = 0; - for (v.cols[at.col].panes[0..v.cols[at.col].n]) |id| column += v.rects[id].h; - const rows: usize = @max(1, @min(Band.Cursor.shown, @max(4, have), column * 2 / 5)); + const rows: usize = @max(1, @min(Band.Cursor.shown, @max(4, have), pk.cap)); // Its second step's rows too: the sources, the acts and what they act on. return @intCast(switch (pk.spine) { .sources => @max(rows, spine_rows.len), @@ -1830,6 +1832,38 @@ test "a picker's band is sized from its list at open, 4 rows at least, and typin try std.testing.expectEqual(rows, p.panes[reader].?.band_rows); } +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" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 30 }); + 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 (0..40) |i| try text.print(std.testing.allocator, "pub fn f{d}() void {{}}\n", .{i}); + const a_path = try testFile(p, &tmp, "alpha.zig", text.items); + 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" }); + p.stream.engine = .walk; + p.sync(); + open(p, asker, .grep, "", "", ""); + const reader = p.paneBySerial(live(p).?.landing).?; + const at_open = p.view().rects[reader].h; + for ("pub fn") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } }); + settle(p); + p.update(.{ .key = .{ .cp = Key.down } }); + 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); +} + 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" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 }); defer p.deinit(); diff --git a/test/snapshots/fsearch.golden b/test/snapshots/fsearch.golden index 59a1b0bb..78de9812 100644 --- a/test/snapshots/fsearch.golden +++ b/test/snapshots/fsearch.golden @@ -67,35 +67,38 @@ |28: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-93 d,#0d1410, 94-96 #59675c,#0d1410, 97-179 #e5eee5,#0d1410, |29: 0-0 d,#608269, 1-89 d,#0d1410, 90-90 d,#608269, 91-179 d,#0d1410, |30: 0-1 d,#1d2824, 2-179 #6f7d75,#1d2824, -== snap list grid=180x31 cursor=110,16 -|16: /tmp/pardes-snap/fsearch/cwd Term+bash Save Mode Filter Collapse Del ^ ‹@p1 › ␣ l /MARK/ 1/3 -|17: ls │ │ Walk Look Split Newcol Grep Edit Copy Keep Drop | Find Grep Recent Panes … -|18: g.txt │ │ ▶ /tmp/pardes-snap/fsearch/cwd/g.txt:2:1: MARK a -|19: │ │ /tmp/pardes-snap/fsearch/cwd/g.txt:6:1: MARK b -|20: │ │ /tmp/pardes-snap/fsearch/cwd/g.txt:10:1: MARK c -|21: │ │ -|22: 1 l1 -|23: 2▸MARK a -|24: 3 l3 -|25: 4 l4 -|26: 5 l5 -|27: 6 MARK b -|28: 7 l7 -|29: 8 l8 +== snap list grid=180x31 cursor=110,15 +|15: ^ ‹@p1 › ␣ l /MARK/ 1/3 +|16: /tmp/pardes-snap/fsearch/cwd Term+bash Save Mode Filter Collapse Del │ │ Walk Look Split Newcol Grep Edit Copy Keep Drop | Find Grep Recent Panes … +|17: ls │ │ ▶ /tmp/pardes-snap/fsearch/cwd/g.txt:2:1: MARK a +|18: g.txt │ │ /tmp/pardes-snap/fsearch/cwd/g.txt:6:1: MARK b +|19: │ │ /tmp/pardes-snap/fsearch/cwd/g.txt:10:1: MARK c +|20: │ │ +|21: 1 l1 +|22: 2▸MARK a +|23: 3 l3 +|24: 4 l4 +|25: 5 l5 +|26: 6 MARK b +|27: 7 l7 +|28: 8 l8 +|29: 9 l9 |30: ⏎ lands here · its text is the preview · S-⏎ a new pane 1 message · SPC h m -== snap ctrln grid=180x31 cursor=110,16 -|16: /tmp/pardes-snap/fsearch/cwd Term+bash Save Mode Filter Collapse Del ^ ‹@p1 › ␣ l /MARK/ 2/3 -|18: g.txt │ │ /tmp/pardes-snap/fsearch/cwd/g.txt:2:1: MARK a -|19: │ │ ▶ /tmp/pardes-snap/fsearch/cwd/g.txt:6:1: MARK b -|22: 3 l3 -|23: 4 l4 -|24: 5 l5 -|25: 6▸MARK b -|26: 7 l7 -|27: 8 l8 -|28: 9 l9 -|29: 10 MARK c +== snap ctrln grid=180x31 cursor=110,15 +|15: ^ ‹@p1 › ␣ l /MARK/ 2/3 +|17: ls │ │ /tmp/pardes-snap/fsearch/cwd/g.txt:2:1: MARK a +|18: g.txt │ │ ▶ /tmp/pardes-snap/fsearch/cwd/g.txt:6:1: MARK b +|21: 3 l3 +|22: 4 l4 +|23: 5 l5 +|24: 6▸MARK b +|25: 7 l7 +|26: 8 l8 +|27: 9 l9 +|28: 10 MARK c +|29: 11 l11 == snap landed grid=180x31 cursor=97,22 +|15: |16: /tmp/pardes-snap/fsearch/cwd Term+bash Save Mode Filter Collapse Del ‹@p1 › +1 › /MARK/ 2/3 › /tmp/pardes-snap/fsearch/cwd/g.txt Keep Save Term Collapse Foll |17: ls ow Del |18: g.txt 2 MARK a |
