diff options
Diffstat (limited to 'core')
| -rw-r--r-- | core/Band.zig | 8 | ||||
| -rw-r--r-- | core/Pick.zig | 264 | ||||
| -rw-r--r-- | core/Query.zig | 2 | ||||
| -rw-r--r-- | core/Trail.zig | 6 | ||||
| -rw-r--r-- | core/layout.zig | 20 |
5 files changed, 218 insertions, 82 deletions
diff --git a/core/Band.zig b/core/Band.zig index 6e8f9589..5efe1a36 100644 --- a/core/Band.zig +++ b/core/Band.zig @@ -141,9 +141,9 @@ pub fn takes(p: *Pardes, id: usize) u16 { /// (UX DESIGN I1, M2): under its tag's rows (`tag`, its rows at rest, which /// no state changes), its head's (`head`), then the band's (`band`), as /// many as the pane has under its tag; `over` the two, drawn over the top -/// rows of its body, which never move for them. A picker's band keeps a -/// body of `body_rows` under it (UX D6), any other state only the pane's -/// rows. Asked of the state alone, as `takes` is: the layout, the frame and +/// rows of its body, which never move for them. A picker's band over the +/// pane its preview shows in keeps a body of `body_rows` under it (UX D6, +/// DESIGN O1), any other only the pane's rows. Asked of the state alone, as `takes` is: the layout, the frame and /// a click ask it of the same step. pub const Covered = struct { tag: u16, head: u16, band: u16, over: u16 }; pub fn covered(p: *Pardes, pane: *const Pane, id: usize) Covered { @@ -153,7 +153,7 @@ pub fn covered(p: *Pardes, pane: *const Pane, id: usize) Covered { // over it to them). const tag = @min(layout.wantedTagRows(p, id), pardes.MAX_TAG_ROWS, @max(pardes.BOX_H, h -| 1)); const head = @min(layout.headRows(p, id), h -| tag); - const keep: u16 = if (p.view().tag_state.kind == .pick) body_rows else 0; + const keep: u16 = if (@import("Pick.zig").previewPane(p, id)) body_rows else 0; const band = @min(takes(p, id), h -| tag -| head -| keep); return .{ .tag = tag, .head = head, .band = band, .over = head + band }; } diff --git a/core/Pick.zig b/core/Pick.zig index e3972419..10f78208 100644 --- a/core/Pick.zig +++ b/core/Pick.zig @@ -1,11 +1,12 @@ //! A picker (pick-ui SPEC.md §5, direction E): a list of places, panes or -//! names unrolled in the tag of the pane its Enter lands in (§3.5): the -//! asking pane when it reads, else its reader, made for the picker when it -//! has none and taken away again by Esc. Its query is typed in that tag's -//! field (TagState.field), its rows hang in the band under it (Band.zig) -//! eleven at a time around the cursor, and that pane's body is the preview: -//! the current row's file at its line, its own text set aside meanwhile and -//! put back when the picker rolls up. +//! names hung under the tag of the pane that asked, which keeps the +//! keyboard (UX DESIGN O1). Its query is typed in the head's field +//! (TagState.field), its rows hang in the band under it (Band.zig) eleven +//! at a time around the cursor, and the body of the pane its Enter lands in +//! is the preview: the current row's file at its line, its own text set +//! aside meanwhile and put back when the picker rolls up. That pane is the +//! asking one when it reads or is untouched, else its reader, else free +//! space, else one made under it for the picker and taken away by Esc. //! //! The rows are Query.zig's producers', re-presented: names scored by //! Names.zig a frame's count at a time (Find's listing from the disk @@ -93,12 +94,13 @@ word: Kind.Buf(24) = .{}, keys: Kind.Buf(4) = .{}, /// Where Find and Grep look; what the rows' paths are relative to. dir: Kind.Buf(4096) = .{}, -/// The pane that asked, and the one its Enter lands in, by serial. +/// The pane that asked, under whose tag it hangs, and the one its Enter +/// lands in, whose body previews, by serial. 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), +/// Its band's rows at most: 40 % of its asking 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, @@ -219,6 +221,16 @@ pub fn previewing(p: *const Pardes, id: usize) bool { return (pk.previewed or pk.source == .actions) and pane.serial == pk.landing; } +/// Whether pane `id` shows the live picker's preview, being its landing +/// pane, for the layout: a body of 60 % kept under what is above it (UX +/// D6, DESIGN O1), the head and the band among that when it asked too. +/// Panes and Themes preview in no pane. +pub fn previewPane(p: *const Pardes, id: usize) bool { + const pk = live(p) orelse return false; + const pane = p.panes[id] orelse return false; + return pane.serial == pk.landing and pk.source != .panes and pk.source != .themes; +} + /// 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, @@ -229,9 +241,9 @@ pub fn landingOf(p: *const Pardes, pane: *const Pane) ?*const Pick { return pk; } -/// 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`). +/// A picker of `source` asked from pane `from`, hung under its tag (UX +/// DESIGN O1), its field `query`. `rows` are a list's (`source` `list`, +/// titled `word`). pub fn open(p: *Pardes, from: usize, source: Source, word: []const u8, query: []const u8, rows: []const u8) void { const asker = p.panes[from] orelse return; TagState.toRest(p); @@ -242,8 +254,8 @@ pub fn open(p: *Pardes, from: usize, source: Source, word: []const u8, query: [] // Find and Grep from the work tree's root (W8), as other finders search. pk.dir.set(if (source == .find or source == .grep) workTree(p, Pardes.paneDir(asker)) else Pardes.paneDir(asker)); pk.rows = p.gpa.dupe(u8, rows) catch |err| return p.reportError(.at(from), "pick", err); + pk.cap = p.view().rects[from].h * 2 / 5; 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); @@ -354,30 +366,28 @@ fn nkept(p: *const Pardes) usize { return n; } -/// Picker `pk` asked from pane `from`: the pane it lands in is `from` when -/// it reads; its reader when it is held and has one; else an untouched -/// pane, `from` itself first (UX J1), which previews as a reading pane does -/// and is given back as it was on Esc; else a pane made where its reader -/// would go, empty until the preview fills it. The keyboard stays where it -/// was: the landing pane is the tag's host. +/// Picker `pk` asked from pane `from`, which keeps the keyboard and hangs +/// its head and band under its tag (UX DESIGN O1). The pane it lands in, +/// whose body previews: `from` when it reads; its reader when it is held +/// and has one; else an untouched pane, `from` itself first (UX J1), which +/// previews as a reading pane does and is given back as it was on Esc; +/// else a pane made where its reader would go, empty until the preview +/// fills it. A source with nothing to preview makes no pane and sets +/// nothing aside: Panes (a row is a pane on the screen), Themes (the whole +/// window wears the row) and code actions (their edit in the asking text). fn hostIn(p: *Pardes, pk: *Pick, from: usize) !void { + defer p.view().active = from; const asker = p.panes[from].?; pk.owner = asker.serial; + pk.landing = asker.serial; pk.made = false; - // A theme is no place: its list is the asking pane's own tag (§3.5), - // and its preview the whole window; an action's is that text's edit. - if (pk.source == .themes or pk.source == .actions) { - pk.landing = asker.serial; - p.view().active = from; - return; - } + if (pk.source == .panes or pk.source == .themes or pk.source == .actions) return; var reader = if (Trail.reading(p, asker)) from else Trail.readerOf(p, asker); if (reader == null) if (layout.freeSpace(p, from, .reader)) |free| if (free == .pane) { reader = free.pane; }; pk.landing = p.panes[reader orelse try landingFor(p, from)].?.serial; pk.made = reader == null; - p.view().active = from; } /// A pane made for a picker where pane `from`'s reader goes: under it, or @@ -393,14 +403,14 @@ fn landingFor(p: *Pardes, from: usize) !usize { return free; } -/// Picker `pk` live in the live view's tag: its host its landing pane, its -/// field `query`, the cursor where it was. +/// Picker `pk` live in the live view's tag: hung under its asking pane's +/// tag (UX DESIGN O1), its field `query`, the cursor where it was. fn unroll(p: *Pardes, pk: *Pick, query: []const u8) void { const v = p.view(); const s = &v.tag_state; s.kind = .pick; s.pick = pk.id; - s.host = pk.landing; + s.host = pk.owner; s.field.set(query); s.rows = .{ .at = @intCast(@min(pk.at, std.math.maxInt(u16))) }; pk.unrolled = true; @@ -996,7 +1006,7 @@ pub fn landingLine(p: *Pardes, arena: std.mem.Allocator, pane: *const Pane) ?usi /// previewing. pub fn sentence(p: *const Pardes, w: *std.Io.Writer) ?[2]usize { const pk = live(p) orelse return null; - if (!pk.previews or pk.source == .themes or pk.source == .actions or pk.source == .lists) return null; + if (!pk.previews or pk.source == .themes or pk.source == .actions or pk.source == .lists or pk.source == .panes) return null; if (pk.landing == pk.owner) { w.writeAll("⏎ lands here") catch return null; } else { @@ -1526,9 +1536,18 @@ fn switchTo(p: *Pardes, pk: *Pick, source: ?Source) void { for (pk.refined[0..pk.nrefined]) |*r| r.names.deinit(p.gpa); pk.nrefined = 0; pk.marks.clearRetainingCapacity(); + const from_panes = pk.source == .panes; pk.source = to; pk.word.set(words.get(to).word); pk.keys.set(words.get(to).keys); + // From Panes, which previews in no pane (hostIn), to a source that + // does: its preview where it would have been had it opened as this one. + if (from_panes and to != .panes) { + var query: Kind.Buf(256) = .{}; + query.set(s.field.text()); + hostIn(p, pk, p.paneBySerial(pk.owner) orelse p.view().active) catch |err| return p.reportError(.at(p.view().active), "pick", err); + unroll(p, pk, query.slice()); + } start(p, pk); filter(p, pk); } @@ -1857,16 +1876,19 @@ pub fn walkList(p: *Pardes, id: usize, forward: bool) bool { } /// Look on a list word in pane `id`'s trail (SPEC §6.3), or a walk onto -/// it at step `walking` (UX L'1): the list unrolled again in that pane's -/// tag, its rows, marks, cursor and query as they were. +/// it at step `walking` (UX L'1): the list unrolled again under that +/// reading pane's tag, which asks it now and previews it, its rows, marks, +/// cursor and query as they were. pub fn reopen(p: *Pardes, id: usize, index: u32, walking: ?u8) void { const pk = byId(p, index) orelse return p.setMessage(.at(id), "walk: that list is gone: the last 8 are kept"); const pane = p.panes[id] orelse return; TagState.toRest(p); p.resume_at = 0; touch(p, pk); + pk.owner = pane.serial; pk.landing = pane.serial; pk.made = false; + p.view().active = id; unroll(p, pk, pk.query.slice()); unrollRows(p, pk); pk.walking = walking; @@ -2189,7 +2211,7 @@ fn settle(p: *Pardes) void { } } -test "a picker from a held pane unrolls in a reader made for it: its rows in the band, the body the current row's file, Esc takes the reader away" { +test "a picker from a held pane hangs under that pane's tag, which keeps the keyboard; its preview in a reader made for it under it, whose tag is `‹@pN ›`: the body the current row's file, Esc takes the reader away (UX DESIGN O1)" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 }); defer p.deinit(); p.settings.jumps = .walk; @@ -2211,12 +2233,13 @@ test "a picker from a held pane unrolls in a reader made for it: its rows in the const npanes = paneCount(p); open(p, asker, .find, "", "", ""); const pk = live(p).?; - // A reader made for it, under the asker; its tag is the picker's. + // A reader made for it, under the asker, which hangs the picker. try std.testing.expectEqual(npanes + 1, paneCount(p)); try std.testing.expect(pk.made); const reader = p.paneBySerial(pk.landing).?; - try std.testing.expectEqual(@as(?usize, reader), TagState.hostOf(p)); + try std.testing.expectEqual(@as(?usize, asker), TagState.hostOf(p)); try std.testing.expectEqual(asker, p.view().active); + try std.testing.expect(p.view().rects[reader].y > p.view().rects[asker].y); settle(p); try std.testing.expectEqual(@as(usize, 2), count(p, pk)); for ("pick") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } }); @@ -2225,19 +2248,20 @@ 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(); - // Its tag the owner's word alone (UX DESIGN M3), the head under it. + // Its tag the owner's word alone (UX DESIGN M3, O1); the head under + // the asker's. 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); + try std.testing.expectEqualStrings("", try headOf(p, a, reader)); + const tag = try headOf(p, a, asker); + try std.testing.expect(std.mem.startsWith(u8, tag, "␣ f Find pick ") and std.mem.indexOf(u8, tag, " 1/1") != null); // The body previews the row's file, after a frame of its own. p.update(.tick); try std.testing.expectEqualStrings(b_path, p.panes[reader].?.file.?.path); _ = try p.render(a); - const r = p.view().rects[reader]; + const r = p.view().rects[asker]; try std.testing.expectEqualStrings("^", p.surface.at(r.x, r.y).grapheme()); - try std.testing.expect(Band.covered(p, p.panes[reader].?, reader).band >= 1); + try std.testing.expect(Band.covered(p, p.panes[asker].?, asker).band >= 1); + try std.testing.expectEqual(@as(u16, 0), Band.covered(p, p.panes[reader].?, reader).over); // 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)); @@ -2259,7 +2283,7 @@ test "a picker's act row is one row under the spines, two cells right of the las Trail.keep(p.panes[asker].?); p.stream.engine = .walk; open(p, asker, .find, "", "", ""); - const reader = p.paneBySerial(live(p).?.landing).?; + const reader = asker; var frame = std.heap.ArenaAllocator.init(std.testing.allocator); defer frame.deinit(); const a = frame.allocator(); @@ -2292,7 +2316,7 @@ test "a picker's band is sized from its list at open, 4 rows at least, and typin p.stream.engine = .walk; open(p, asker, .find, "", "", ""); settle(p); - const reader = p.paneBySerial(live(p).?.landing).?; + const reader = asker; p.sync(); const rows = Band.covered(p, p.panes[reader].?, reader).band; // One or two files listed: four rows, ground under them. @@ -2304,7 +2328,7 @@ test "a picker's band is sized from its list at open, 4 rows at least, and typin 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" { +test "a picker's band is capped once at open at 40 % of its asking pane's rows; the pane it previews in borrows from its column for a body of 60 %: a Grep from a held pane at 100x30 previews 8 rows at least, in a reader made under it (UX D6, DESIGN O1)" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 30 }); defer p.deinit(); p.settings.jumps = .walk; @@ -2322,20 +2346,21 @@ test "a picker's band is capped once at open at 40 % of its host pane's rows; th 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(); + const at_open = p.view().rects[asker].h; open(p, asker, .grep, "", "", ""); const reader = p.paneBySerial(live(p).?.landing).?; - const at_open = p.view().rects[reader].h; + try std.testing.expect(reader != asker); for ("pub fn") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } }); settle(p); p.update(.{ .key = .{ .cp = Key.down } }); + p.update(.tick); p.sync(); - const pane = p.panes[reader].?; - const r = p.view().rects[reader]; - const at = Band.covered(p, pane, reader); + const at = Band.covered(p, p.panes[asker].?, asker); 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 - (at.tag + at.over); + // The preview's rows under the reader's tag, no band over them. + const r = p.view().rects[reader]; + try std.testing.expectEqual(@as(u16, 0), Band.covered(p, p.panes[reader].?, reader).over); + const under = r.h - p.panes[reader].?.tag_rows; try std.testing.expect(under >= 8); try std.testing.expect(@as(u32, under) * 5 >= @as(u32, r.h) * 3); } @@ -3722,7 +3747,7 @@ test "Find and Grep search the work tree (W8): from a pane deep in a repo Find l 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)" { +test "a pane made for a picker has no rest: its tag is its owner's word alone, `‹@pN ›`, its body under it; the head hangs under the asking pane's tag (UX DESIGN M3, O1)" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 }); defer p.deinit(); p.settings.jumps = .walk; @@ -3752,20 +3777,125 @@ test "a pane made for a picker has no rest: its tag is its owner's word alone, ` const s = try p.render(a); const r = p.view().rects[reader]; var row: std.ArrayList(u8) = .empty; - for (0..2) |y| { + const ra = p.view().rects[asker]; + for ([_]struct { y: u16, starts: []const u8 }{ + // The tag's row, the owner's word; the body's under it. + .{ .y = r.y, .starts = std.mem.trimEnd(u8, owner, " ") }, + .{ .y = r.y + 1, .starts = "1▸const alpha" }, + // The head under the asker's tag. + .{ .y = ra.y + p.panes[asker].?.tag_rows, .starts = "␣ f Find " }, + }) |want| { 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 ")); + for (s.cells[@as(usize, want.y) * s.cols + r.x + pardes.TAG_TEXT_INSET ..][0 .. r.w - pardes.TAG_TEXT_INSET]) |cell| try row.appendSlice(a, cell.grapheme()); + try std.testing.expect(std.mem.startsWith(u8, std.mem.trimStart(u8, row.items, " "), want.starts)); } - // 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); + p.update(.{ .key = .{ .cp = Key.escape } }); 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 }); +} + +test "SPC b b from a held pane hangs under that pane's own tag (UX DESIGN O1): no pane made, nothing set aside, the keyboard in its field; a Panes list never names a picker's preview" { + 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(); + const b_path = try testFile(p, &tmp, "beta.zig", "one\ntwo\nthree\n"); + defer p.gpa.free(b_path); + _ = try p.setTestFile("held\n"); + const held = p.view().active; + Trail.keep(p.panes[held].?); + exec.runBuiltin(p, .New, held, "New", null); + p.view().active = held; + p.sync(); + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + const a = frame.allocator(); + const rest = try a.dupe(u8, try tagOf(p, a, held)); + const npanes = paneCount(p); + for (" bb") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } }); + const pk = live(p).?; + try std.testing.expectEqual(Source.panes, pk.source); + try std.testing.expectEqual(npanes, paneCount(p)); + try std.testing.expect(!pk.made); + try std.testing.expectEqual(p.panes[held].?.serial, pk.landing); + try std.testing.expectEqual(@as(?usize, held), TagState.hostOf(p)); + try std.testing.expectEqual(held, p.view().active); + try std.testing.expectEqualStrings(rest, try tagOf(p, a, held)); + try std.testing.expect(std.mem.startsWith(u8, try headOf(p, a, held), "␣ b Panes ")); + settle(p); + p.update(.tick); + // Nothing previewed, nothing said of a preview: the held pane's own text. + try std.testing.expect(pk.aside == null and p.panes[held].?.file.?.output == null); + var said: [256]u8 = undefined; + var w: std.Io.Writer = .fixed(&said); + try std.testing.expect(sentence(p, &w) == null); + try std.testing.expectEqual(@as(usize, 2), count(p, pk)); + p.update(.{ .key = .{ .cp = Key.escape } }); + try std.testing.expectEqual(npanes, paneCount(p)); + // A list from the held pane previews in the untouched +New (UX J1); + // switched to Panes, the +New previewing is not among its rows. + const rows = try std.fmt.allocPrint(a, "{s}:3:1 three\n", .{b_path}); + open(p, held, .list, "Refs", "", rows); + settle(p); + p.update(.tick); + const scratch = p.paneBySerial(live(p).?.landing).?; + try std.testing.expect(scratch != held); + try std.testing.expectEqualStrings(b_path, p.panes[scratch].?.file.?.path); + p.update(.{ .key = .{ .cp = 'h', .alt = true } }); + p.update(.{ .key = .{ .cp = 'b', .text = "b" } }); + try std.testing.expectEqual(Source.panes, live(p).?.source); + try std.testing.expectEqual(@as(usize, 1), count(p, live(p).?)); + p.update(.{ .key = .{ .cp = Key.escape } }); + try std.testing.expect(Trail.untouched(p, p.panes[scratch].?)); +} + +test "a picker from a held pane with a reader hangs under the held pane's tag and previews in the reader, whose tag names its own file; Esc gives the reader its text back; switched from Panes, it previews where it would have (UX DESIGN O1)" { + 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(); + const a_path = try testFile(p, &tmp, "alpha.zig", "const alpha = 1;\n"); + defer p.gpa.free(a_path); + const b_path = try testFile(p, &tmp, "beta.zig", "one\ntwo\nthree\n"); + defer p.gpa.free(b_path); + _ = try p.setTestFile("held\n"); + const held = p.view().active; + Trail.keep(p.panes[held].?); + // Its reader: alpha.zig, a Look from it. + _ = look.open(p, held, a_path, .{ .line = 1, .col = 1 }, .replace); + p.sync(); + const reader = Trail.readerOf(p, p.panes[held].?).?; + try std.testing.expectEqualStrings(a_path, p.panes[reader].?.file.?.path); + p.view().active = held; + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + const a = frame.allocator(); + const reader_tag = try a.dupe(u8, try tagOf(p, a, reader)); + const npanes = paneCount(p); + const rows = try std.fmt.allocPrint(a, "{s}:3:1 three\n", .{b_path}); + open(p, held, .list, "Refs", "", rows); + settle(p); + p.update(.tick); + const pk = live(p).?; + try std.testing.expectEqual(npanes, paneCount(p)); + try std.testing.expectEqual(p.panes[reader].?.serial, pk.landing); + try std.testing.expectEqual(@as(?usize, held), TagState.hostOf(p)); + try std.testing.expectEqualStrings(b_path, p.panes[reader].?.file.?.path); + try std.testing.expectEqualStrings(reader_tag, try tagOf(p, a, reader)); + try std.testing.expectEqual(@as(i32, 2), p.panes[reader].?.body.cur_row); + p.update(.{ .key = .{ .cp = Key.escape } }); + try std.testing.expectEqualStrings(a_path, p.panes[reader].?.file.?.path); + try std.testing.expect(p.panes[reader].?.file.?.output == null); + // Panes first, from the held pane: nothing set aside; then M-h r, + // Recent, previews in the reader as a list opened there would. + open(p, held, .panes, "", "", ""); + try std.testing.expectEqual(p.panes[held].?.serial, live(p).?.landing); + p.update(.{ .key = .{ .cp = 'h', .alt = true } }); + p.update(.{ .key = .{ .cp = 'r', .text = "r" } }); + try std.testing.expectEqual(Source.recent, live(p).?.source); + try std.testing.expectEqual(p.panes[reader].?.serial, live(p).?.landing); + try std.testing.expectEqual(@as(?usize, held), TagState.hostOf(p)); + p.update(.{ .key = .{ .cp = Key.escape } }); + try std.testing.expectEqualStrings(a_path, p.panes[reader].?.file.?.path); } diff --git a/core/Query.zig b/core/Query.zig index f9651faf..96047ca1 100644 --- a/core/Query.zig +++ b/core/Query.zig @@ -749,6 +749,8 @@ pub fn gather(p: *Pardes, names: *Names, source: Source, dir: []const u8, self: for (p.panes) |slot| { const other = slot orelse continue; if (other == self or other.query != null) continue; + // A picker's preview is no pane to go to (UX DESIGN O1). + if (other.file) |f| if (f.output) |o| if (o.from == .preview) continue; var buf: [4096 + 32]u8 = undefined; const what: []const u8 = if (other.file) |f| f.path else if (other.command) |c| c else other.cwdSlice(); const row = std.fmt.bufPrint(&buf, config.pane_addr ++ "{d} {s}", .{ other.serial, relative(what, dir) }) catch continue; diff --git a/core/Trail.zig b/core/Trail.zig index e07e4357..f6cfec9a 100644 --- a/core/Trail.zig +++ b/core/Trail.zig @@ -948,10 +948,12 @@ test "the walk drawn with a picker's list and the notice row (walk UI G 2e, SPEC f.look(f.held, "rank.zig", 12); const r = p.view().active; // A list asked from the held pane (SPC e's places, a server's answer): - // its Enter lands in the reader, nothing made. + // hung under the held pane's tag (UX DESIGN O1), its Enter lands in the + // reader, nothing made. const rows = try std.fmt.bufPrint(&buf, "{s}/place.zig:8:1 of\n{s}/place.zig:40:1 Span\n", .{ f.dir, f.dir }); pardes.Pick.open(p, f.held, .list, "Refs", "", rows); - try std.testing.expectEqual(p.panes[r].?.serial, p.view().tag_state.host); + try std.testing.expectEqual(owner, p.view().tag_state.host); + try std.testing.expectEqual(p.panes[r].?.serial, pardes.Pick.live(p).?.landing); pardes.Pick.landHere(p); p.sync(); // The reader stepped (to another file: a pane of its own, its owner's diff --git a/core/layout.zig b/core/layout.zig index ae15c6e9..b15c7200 100644 --- a/core/layout.zig +++ b/core/layout.zig @@ -1608,22 +1608,24 @@ pub fn compute(p: *Pardes) void { /// `min_body_rows` (a shorter one loses its prompt and reads busy for /// ever), a text pane may shrink to its tag, as acme's windows do. A tag /// out of rest has the rows for its head and its band under it, drawn over -/// its body (UX DESIGN I1, M4); a picker's (code actions' too: its body is -/// the preview) a body of 60 % of the pane and 6 rows at least under them -/// (UX D6). Those are borrowed from the column's other panes, which shrink -/// to their tags until it rolls up (walk UI SPEC §3.6). A terminal's and a -/// kind's size is their user's: a transient state never resizes the pty -/// under a program or a kind's view (a PDF's), it is drawn over as much of -/// them as it has (R3). +/// its body (UX DESIGN I1, M4). The pane a picker's preview shows in (code +/// actions' asking pane too: its body is the preview) has a body of 60 % of +/// the pane and 6 rows at least under its tag, and its head and band when +/// it asked (UX D6, DESIGN O1). Those are borrowed from the column's other +/// panes, which shrink to their tags until it rolls up (walk UI SPEC +/// §3.6). A terminal's and a kind's size is their user's: a transient +/// state never resizes the pty under a program or a kind's view (a PDF's), +/// it is drawn over as much of them as it has (R3). fn floorRows(p: *Pardes, id: usize) u16 { const pane = p.panes[id] orelse return 0; const under = if (pane.isTerminal() or pane.addon != null) 0 else headRows(p, id) + pardes.Band.takes(p, id); - if (under > 0) { + const preview = pardes.Pick.previewPane(p, id); + if (under > 0 or preview) { // Worked out from the state, never the last sync's rows (the first // layout after a head changed read the rows of the one before, and // the next moved the body). const above = wantedTagRows(p, id) + under; - if (p.view().tag_state.kind != .pick) return above; + if (!preview) return above; // A body of 60 % is one and a half times what is above it. return above + @max(pardes.Band.body_rows, (3 * above + 1) / 2); } |
