diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-25 12:38:27 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-25 12:50:44 -0300 |
| commit | e6c384833912598d65c509f0d3a7b713fab0a8eb (patch) | |
| tree | 8392991253b366e4152df327528ba1c4f8af005f /core | |
| parent | 46f004ba04ad6d6299c8967d6890b8f7110db88a (diff) | |
| parent | 7e4d1d727487455376c54695bb13683b9d1e5cc9 (diff) | |
| download | pardes-e6c384833912598d65c509f0d3a7b713fab0a8eb.tar.gz pardes-e6c384833912598d65c509f0d3a7b713fab0a8eb.zip | |
walk UI M9: X3's seed 109/162 fix (wkylslmo 7e4d1d727487, one change on X2's suvlqwul: a walk step never refuses and never takes a row its column cannot give: a walked reading pane's tag at rest folds to its newest step, then cuts its path from the left, `…` and the basename whole, worked out each time from the pane's own rect by tagline.folded (Fold{whole, cut, squeezed}), restPath writing the cut name; Trail.lift takes a row at a time from the column (layout.giveRow) while the column has one; draw.zig tagTintRange/paintPaneTag and Prompt.unlit take `.whole`; the tree.zig placement test runs under the walk default, 300 seeds) merged onto M8 (tspqtroz), resolved by meaning: no text conflict (X3's tagline, Trail, layout.giveRow and its one-line hunks in draw.zig and Prompt.zig sit beside X1's and X2's); THE ORDER X3 ASKED TO CHECK: X1 (E5.2) gives each pane of a column its width before its height in layout.compute, so that a band host's floor (floorRows: max(wantedTagRows, headRows + band)) wraps its tag at the width it will have; compute starts from zeroed rects, so in that pass a pane has `w` and `h == 0`; X3's folded reads both: on X3's own tree `w == 0` there returned before any cut (and wantedTagRows returned the last sync's rows); on the merge `h == 0` read as a pane with no rows, so a walked reading pane hosting a band had its path cut to its basename in the floor while the sync after it, with the real height, kept it whole: the floor counted fewer rows above the body than the tag took; RUN (TEST FIRST): Trail.zig "a band on a walked reading pane keeps it a body of 60 % ..." (40 columns, the reader's path some 230 cells, its tag at rest 6 rows or more; its share of the column swept from 12 rows to 30, Help with a query nothing matches, a 4-row band): fails on the merge at Trail.zig:1019, the body under 60 % of the pane (UX D6, E3); a user could have hit it on a walked reading pane with a long path in a narrow column, any band (a level, Help, a picker) opened on it; THE FIX (tagline.folded): `r.h == 0` reads as not laid out, as `r.w == 0` does: no cut, the tag at rest whole; the floor then reserves the whole tag and the sync, given at least that many rows, finds it fits: both count the same rows; where the column cannot give them, the sync cuts as X3 does; the witnesses X3 named pass: tree.zig "random placements, refused or not ..." (shell-test, filtered 8/8) and P1's Pick "after Enter the list is a word in the reader's trail ..." (core-test, filtered 11/11); core-test 1097/1268 (171 skipped: M8's 1095 + X3's test + this one), process-test 0 of 147 failed (3 skipped): no golden moved
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE
Diffstat (limited to 'core')
| -rw-r--r-- | core/Prompt.zig | 2 | ||||
| -rw-r--r-- | core/Trail.zig | 137 | ||||
| -rw-r--r-- | core/draw.zig | 8 | ||||
| -rw-r--r-- | core/layout.zig | 31 | ||||
| -rw-r--r-- | core/ninep/tree.zig | 5 | ||||
| -rw-r--r-- | core/tagline.zig | 108 |
6 files changed, 257 insertions, 34 deletions
diff --git a/core/Prompt.zig b/core/Prompt.zig index ad2cfbed..0a288a79 100644 --- a/core/Prompt.zig +++ b/core/Prompt.zig @@ -811,7 +811,7 @@ pub fn execWord(p: *Pardes, id: usize) void { pub fn unlit(p: *const Pardes, pane: *Pane) ?[2]usize { if (Trail.outOfRest(p, pane)) return null; const t = &pane.trail; - const whole = pardes.tagline.folded(p, pane); + const whole = pardes.tagline.folded(p, pane).whole; for (t.steps[0..t.cur], 0..) |*step, i| if (step.* == .search) { if (lights(pane, &step.search) or t.isFolded(i, whole)) return null; return t.spanOf(i, whole); diff --git a/core/Trail.zig b/core/Trail.zig index c2c1b0c3..ddc350ca 100644 --- a/core/Trail.zig +++ b/core/Trail.zig @@ -244,12 +244,16 @@ fn show(p: *Pardes, id: usize, path: []const u8, at: Spot) !usize { /// Pane `id`'s tag after a step may take more rows than it had (its walk's /// words, a longer name): it is given them from its column, as a step that /// wraps tags gives them (layout.restoreMinimaFrom), the others keeping -/// their own minimum. +/// their own minimum: a row at a time while its tag is folded to its newest +/// step or its path cut for want of them (tagline.folded). What the column +/// cannot give, the step never takes: the tag stays cut. fn lift(p: *Pardes, id: usize) void { const now = p.view().rects; var floor = layout.minima(p); floor[id] = 0; layout.restoreMinimaFrom(p, &now, &floor); + const pane = p.panes[id] orelse return; + while (pardes.tagline.folded(p, pane).squeezed and layout.giveRow(p, id)) {} } /// `s`, a search's or a recipe's word, the pane's one of its kind (§7.3, @@ -722,13 +726,17 @@ test "the reader of a held pane too short to halve goes to the bottom of the nex try std.testing.expectEqual(col + 1, layout.findPane(f.p, reader_id).?.col); } -/// Where `word` starts in pane `id`'s tag, on the screen. +/// Where `word` starts in pane `id`'s tag, on the screen: on whichever of +/// its rows the tag wrapped it onto. fn tagCell(p: *Pardes, id: usize, word: []const u8) ![2]u16 { const pane = p.panes[id].?; const tag = try tagOf(p, pane); const i = std.mem.indexOf(u8, tag, word) orelse return error.NotInTag; + const shown = try pardes.tagline.shownTag(p, p.scratch.allocator(), pane); + const at = modal.positionAt(shown.text, shown.fromReal(i)); + const col = panes.File.rawDisplayCol(p.settings.tab, modal.lineSlice(shown.text, at.row), at.col); const r = p.view().rects[id]; - return .{ r.x + pardes.TAG_TEXT_INSET + @as(u16, @intCast(panes.File.displayWidth(p.settings.tab, tag[0..i]))), p.tagTop(pane, r) }; + return .{ r.x + pardes.TAG_TEXT_INSET + @as(u16, @intCast(col)), p.tagTop(pane, r) + @as(u16, @intCast(at.row)) }; } /// A click with `button` on `word` in pane `id`'s tag: a press and a @@ -892,6 +900,129 @@ test "the walk never adds a row to a tag at rest: its steps fold further, down t try std.testing.expect(std.mem.indexOf(u8, try tagOf(p, pane), " › +") != null); } +test "a step whose tag would take a row its column cannot give folds to its newest step and cuts its path from the left, `…` and the basename whole, and takes no row; a column with a row to give grows its tag as before" { + var f: Fixture = .{ .p = undefined, .tmp = undefined }; + try f.init(60); + defer f.deinit(); + const p = f.p; + const v = p.view(); + // A path some 115 cells longer than rank.zig's, wider than a tag's row + // here: its tag wraps onto a row more than rank.zig's. + const deep = "a-directory-whose-name-runs-on-past-a-tag-row/" ++ "and-one-more-whose-name-runs-on-as-well/" ++ "and-a-third-for-good-measure/long.zig"; + try f.tmp.dir.createDirPath(std.testing.io, std.Io.Dir.path.dirname(deep).?); + try f.tmp.dir.writeFile(std.testing.io, .{ .sub_path = deep, .data = "a\nb\nc\nd\n" }); + var full_buf: [4096 + 256]u8 = undefined; + const full = try std.fmt.bufPrint(&full_buf, "{s}/{s}", .{ f.dir, deep }); + f.look(f.held, "rank.zig", 12); + var r = v.active; + const c = layout.findPane(p, r).?.col; + // Its column with no row to give: every pane at its minimum. + var need: u16 = 0; + for (v.cols[c].panes[0..v.cols[c].n]) |k| need += layout.minRows(p, k); + p.update(.{ .resize = .{ .cols = 120, .rows = need + p.topBarHeight() + layout.columnBarHeight(p) + layout.noticeRowHeight(p) } }); + try std.testing.expect(layout.shareColumn(p, c)); + for (v.cols[c].panes[0..v.cols[c].n]) |k| try std.testing.expectEqual(layout.minRows(p, k), v.rects[k].h); + const before = v.rects[r]; + f.look(r, deep, 2); + r = v.active; + // In place, its rows as they were, every pane at its minimum. + try std.testing.expectEqual(before, v.rects[r]); + try std.testing.expect(layout.columnAtMinimums(p, c)); + const pane = p.panes[r].?; + try std.testing.expectEqualStrings(full, pane.file.?.path); + // `‹@pN › rank.zig:12 › …` and the path's end, its basename whole. + var tag = try tagOf(p, pane); + var at: [64]u8 = undefined; + const lead = try std.fmt.bufPrint(&at, "‹@p{d} › rank.zig:12 › …", .{p.panes[f.held].?.serial}); + try std.testing.expect(std.mem.startsWith(u8, tag, lead)); + var shown = tag[lead.len..std.mem.indexOf(u8, tag, " Keep ").?]; + try std.testing.expect(shown.len < full.len and std.mem.endsWith(u8, full, shown) and std.mem.endsWith(u8, shown, "/long.zig")); + // A step on to a short path and back: the cut again, its forward step + // after it, dimmed where it is; the basename in the name's ink. + f.look(r, "place.zig", 5); + try clickTag(p, v.active, "long.zig:2", .right); + r = v.active; + try std.testing.expectEqual(before, v.rects[r]); + try std.testing.expect(layout.columnAtMinimums(p, c)); + tag = try tagOf(p, p.panes[r].?); + try std.testing.expect(std.mem.startsWith(u8, tag, lead)); + const ahead = pardes.tagline.forwardSpan(p, p.panes[r].?); + try std.testing.expectEqualStrings(" › place.zig:5", tag[ahead[0]..ahead[1]]); + shown = tag[lead.len..ahead[0]]; + try std.testing.expect(std.mem.endsWith(u8, full, shown) and std.mem.endsWith(u8, shown, "/long.zig")); + var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer arena.deinit(); + const s = try p.render(arena.allocator()); + const base = try tagCell(p, r, "long.zig"); + try std.testing.expectEqual(pardes.Color{ .rgb = p.chromeTheme().tag_active_name_fg }, s.at(base[0], base[1]).style.fg); + // A click on the path drafts a name: the whole path, its caret where + // the click was (on the first byte shown after the `…`). + const after = v.rects[r]; + const cell = after.x + pardes.TAG_TEXT_INSET + @as(u16, @intCast(panes.File.displayWidth(p.settings.tab, lead))); + for ([_]pardes.Mouse.Kind{ .press, .release }) |kind| p.update(.{ .mouse = .{ .button = .left, .kind = kind, .col = cell, .row = p.tagTop(p.panes[r].?, after) } }); + p.sync(); + try std.testing.expect(p.panes[r].?.prompt == .name); + try std.testing.expectEqualStrings(full, p.panes[r].?.input.own.?); + try std.testing.expectEqual(@as(i32, @intCast(full.len - shown.len)), p.panes[r].?.input.cur_col); + p.update(.{ .key = .{ .cp = pardes.Key.escape } }); + // Back to rank.zig, a row to give in the column's first pane: the step + // to the long path grows the tag as before, the whole path in it. + try clickTag(p, r, "rank.zig:12", .right); + r = v.active; + p.update(.{ .resize = .{ .cols = 120, .rows = v.screen_h + 6 } }); + for (v.cols[c].panes[0..v.cols[c].n]) |k| p.panes[k].?.vweight = @floatFromInt(layout.minRows(p, k)); + p.panes[v.cols[c].panes[0]].?.vweight += 6; + layout.compute(p); + const short = v.rects[r]; + f.look(r, deep, 2); + r = v.active; + try std.testing.expect(v.rects[r].h > short.h); + try std.testing.expect(layout.columnAtMinimums(p, c)); + tag = try tagOf(p, p.panes[r].?); + try std.testing.expect(std.mem.indexOf(u8, tag, "…") == null and std.mem.indexOf(u8, tag, full) != null); +} + +test "a band on a walked reading pane keeps it a body of 60 %: the layout's floor counts its tag at rest whole, as the sync after it keeps it (a pane the layout has given its width and not yet its height is never cut)" { + var f: Fixture = .{ .p = undefined, .tmp = undefined }; + try f.init(60); + defer f.deinit(); + const p = f.p; + const v = p.view(); + const deep = "a-directory-whose-name-runs-on-past-a-tag-row/" ++ "and-one-more-whose-name-runs-on-as-well/" ++ "and-a-third-for-good-measure/long.zig"; + try f.tmp.dir.createDirPath(std.testing.io, std.Io.Dir.path.dirname(deep).?); + try f.tmp.dir.writeFile(std.testing.io, .{ .sub_path = deep, .data = "a\nb\nc\nd\n" }); + f.look(f.held, "rank.zig", 12); + f.look(v.active, deep, 2); + const r = v.active; + const pane = p.panes[r].?; + try std.testing.expect(reading(p, pane)); + // Narrow: its tag at rest takes more rows than Help's head and band. + p.update(.{ .resize = .{ .cols = 40, .rows = 60 } }); + p.sync(); + try std.testing.expect(pane.tag_rows > 5); + const c = layout.findPane(p, r).?.col; + const col = v.cols[c].panes[0..v.cols[c].n]; + try std.testing.expect(col.len > 1); + var rows: u16 = 0; + for (col) |k| rows += v.rects[k].h; + // Its share of the column at every height from 12 rows to 30 (its tag + // at rest whole); Help with a query nothing matches: a 4-row band. + var h: u16 = 12; + while (h <= 30) : (h += 1) { + for (col) |k| p.panes[k].?.vweight = if (k == r) @floatFromInt(h) else @as(f32, @floatFromInt(rows - h)) / @as(f32, @floatFromInt(col.len - 1)); + layout.compute(p); + p.sync(); + for ([_]u21{ ' ', '?', 'q', 'q', 'x', 'q' }) |key| p.update(.{ .key = .{ .cp = key, .text = &[_]u8{@intCast(key)} } }); + p.sync(); + try std.testing.expect(pane.band_rows > 0); + const at = v.rects[r]; + try std.testing.expect((at.h - pane.tag_rows) * 5 >= at.h * 3); + p.update(.{ .key = .{ .cp = pardes.Key.escape } }); + p.sync(); + try std.testing.expect(pardes.TagState.hostOf(p) == null); + } +} + test "two steps whose files have the same name are told apart by the shortest path they do not share; the word n walks is underlined" { var f: Fixture = .{ .p = undefined, .tmp = undefined }; try f.init(60); diff --git a/core/draw.zig b/core/draw.zig index 685f67ea..8f690e8e 100644 --- a/core/draw.zig +++ b/core/draw.zig @@ -721,7 +721,11 @@ fn tagTintRange(p: *const Pardes, pane: *const Pane, tag: []const u8, prefix_len } else return null; const basename = if (std.mem.lastIndexOfScalar(u8, name, '/')) |slash| slash + 1 else 0; if (basename == name.len) return null; - return .{ .lo = start + basename, .hi = start + name.len }; + // A walked file's path cut from its left: a `…` for the bytes it drops + // (tagline.folded), never its basename's. + const cut = if (pane.file != null) tagline.folded(p, pane).cut else 0; + const dots: usize = if (cut > 0) "…".len else 0; + return .{ .lo = start + dots + basename - cut, .hi = start + dots + name.len - cut }; } /// A header or a notice band as a tag layer: `viewport.h` rows, line `top` @@ -1102,7 +1106,7 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, const ahead = tagline.forwardSpan(p, pane); if (ahead[0] < ahead[1]) inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, ahead[0], @min(ahead[1], first_line.len), inks.dim, false); if (pane.file != null and pane.trail.n > 0 and !pardes.Trail.outOfRest(p, pane)) { - const kept = tagline.folded(p, pane); + const kept = tagline.folded(p, pane).whole; const t = &pane.trail; const first: usize = @intFromBool(t.steps[0] == .owner); if (t.isFolded(first, kept)) { diff --git a/core/layout.zig b/core/layout.zig index 9c15833d..4b5b7d2c 100644 --- a/core/layout.zig +++ b/core/layout.zig @@ -586,7 +586,9 @@ pub fn acmePlace(p: *Pardes, c: usize, origin: ?usize, id: usize) void { pub const min_body_rows = 2; /// The rows pane `id`'s tag takes at its width, wrapped as `sync` wraps -/// it: what a placement must leave it above its body rows. +/// it: what a placement must leave it above its body rows. A walked file's +/// path is cut to the rows its pane has (tagline.folded): its tag never +/// wants a row more. pub fn wantedTagRows(p: *Pardes, id: usize) u16 { const pane = p.panes[id] orelse return BOX_H; if (pane.collapsed or !pane.tag_expanded) return BOX_H; @@ -744,6 +746,33 @@ pub fn restoreMinimaFrom(p: *Pardes, before: *const [MAX_PANES]Rect, before_min: compute(p); } +/// One row more for pane `id` from whichever pane of its column has the +/// most above its own minimum, as restoreMinimaFrom gives them; false, +/// changing nothing, when none has one (or the column holds a folded +/// pane). +pub fn giveRow(p: *Pardes, id: usize) bool { + const v = p.view(); + compute(p); + const c = (findPane(p, id) orelse return false).col; + const col = v.cols[c].panes[0..v.cols[c].n]; + var giver: ?usize = null; + var spare: u16 = 0; + for (col) |k| { + const pane = p.panes[k] orelse return false; + if (pane.collapsed) return false; + if (k != id and v.rects[k].h -| minRows(p, k) > spare) { + spare = v.rects[k].h - minRows(p, k); + giver = k; + } + } + const g = giver orelse return false; + for (col) |k| p.panes[k].?.vweight = @floatFromInt(@max(1, v.rects[k].h)); + p.panes[g].?.vweight -= 1; + p.panes[id].?.vweight += 1; + compute(p); + return true; +} + /// Column `c`'s rows for `id`, last in it, at its minimum: a row at a /// time from whichever pane has the most above its own minimum, so a pane /// dragged short keeps its rows and the others give only what they must. diff --git a/core/ninep/tree.zig b/core/ninep/tree.zig index 4feb0153..01cfe297 100644 --- a/core/ninep/tree.zig +++ b/core/ninep/tree.zig @@ -2013,11 +2013,6 @@ test "random placements, refused or not, leave no pane under its tag and two row const rows = r.intRangeAtMost(u16, 6, 40); const p = try pardes.Pardes.init(testing.allocator, .{ .tty_only = true, .cols = r.intRangeAtMost(u16, 60, 240), .rows = rows }); defer p.deinit(); - // Placements as a Look made them before the walk: `Jumps new-pane` - // (SPEC §6.6). Under the walk a step in place can wrap its tag in a - // column with no rows to give (seed 109): the trail's give-way, - // not a placement's refusal (Trail.lift lifts it when there are). - p.settings.jumps = .@"new-pane"; while (p.nextEffect()) |_| {} _ = try p.setTestFile("x\n"); while (p.nextEffect()) |_| {} diff --git a/core/tagline.zig b/core/tagline.zig index 5f7222e6..0ec26d2f 100644 --- a/core/tagline.zig +++ b/core/tagline.zig @@ -177,14 +177,17 @@ fn restPath(p: *const Pardes, arena: std.mem.Allocator, pane: *Pane) ![]const u8 const keep = pardes.Trail.reading(p, pane); if (pane.trail.n == 0 and !keep) return name; // Its walk's back steps before the name, its forward steps after - // it (Trail.zig), in the room `bytes` measures them. + // it (Trail.zig), in the room `bytes` measures them; a name its + // tag has not the rows for cut from the left (`folded`). const keep_word = if (keep) " Keep" else ""; - const whole = folded(p, pane); - const room = try arena.alloc(u8, pane.trail.bytes(.back, whole) + name.len + pane.trail.bytes(.forward, whole) + keep_word.len); + const fold = folded(p, pane); + const dots = if (fold.cut > 0) "…" else ""; + const room = try arena.alloc(u8, pane.trail.bytes(.back, fold.whole) + dots.len + name.len - fold.cut + pane.trail.bytes(.forward, fold.whole) + keep_word.len); var w: std.Io.Writer = .fixed(room); - pane.trail.write(.back, whole, &w) catch return error.OutOfMemory; - w.writeAll(name) catch return error.OutOfMemory; - pane.trail.write(.forward, whole, &w) catch return error.OutOfMemory; + pane.trail.write(.back, fold.whole, &w) catch return error.OutOfMemory; + w.writeAll(dots) catch return error.OutOfMemory; + w.writeAll(name[fold.cut..]) catch return error.OutOfMemory; + pane.trail.write(.forward, fold.whole, &w) catch return error.OutOfMemory; w.writeAll(keep_word) catch return error.OutOfMemory; return w.buffered(); } @@ -201,26 +204,79 @@ fn restPath(p: *const Pardes, arena: std.mem.Allocator, pane: *Pane) ![]const u8 /// Where a file's name starts in its tag: after its walk's back steps. pub fn nameAt(p: *const Pardes, pane: *const Pane) usize { - return if (pane.file != null and pane.trail.n > 0) pane.trail.bytes(.back, folded(p, pane)) else 0; + return if (pane.file != null and pane.trail.n > 0) pane.trail.bytes(.back, folded(p, pane).whole) else 0; } +/// How a file's tag at rest writes its walk and its name (UX D8, D2). +pub const Fold = struct { + /// The newest back steps written whole; older ones fold into `+N`. + whole: usize = pardes.Trail.shown_steps, + /// The bytes its name drops from its left, a `…` in their place. + cut: usize = 0, + /// Its tag, its name whole, wants more rows than its pane has over + /// `layout.min_body_rows`: Trail.lift grows it while its column has a + /// row to give. + squeezed: bool = false, +}; + /// The back steps a file's tag writes whole at rest (UX D8): the newest /// three (Trail.shown_steps), fewer, down to the newest alone, while its /// walk would make the tag take more rows than it takes with none: the /// walk never adds a row to a tag at rest (as far as the newest alone -/// lets it). -pub fn folded(p: *const Pardes, pane: *const Pane) usize { +/// lets it). A pane that walked (a step besides its owner and where it +/// is) whose tag still wants more rows than the pane has over +/// `layout.min_body_rows` keeps its newest step alone and cuts its path +/// from the left to fit them, its basename always whole (UX D2; the +/// coordinator's ruling on seeds 109 and 162: a step never refuses and +/// never takes a row its column cannot give). Rows are counted in cells, +/// as a tag at rest wraps (UX E4, P1's reading 9). +pub fn folded(p: *const Pardes, pane: *const Pane) Fold { const t = &pane.trail; - const f = pane.file orelse return pardes.Trail.shown_steps; - if (t.n == 0) return pardes.Trail.shown_steps; - const id = panes.paneIdOf(p, pane) orelse return pardes.Trail.shown_steps; + const f = pane.file orelse return .{}; + if (t.n == 0) return .{}; + const id = panes.paneIdOf(p, pane) orelse return .{}; const tab = p.settings.tab; const width = tagWidth(p, id); const name = if (pane.prompt == .name) pane.input.own orelse f.path else f.path; - const bare = panes.File.displayWidth(tab, name) + @as(usize, if (pardes.Trail.reading(p, pane)) " Keep".len else 0) + panes.File.displayWidth(tab, curTail(pane)); + const keep = pardes.Trail.reading(p, pane); + const tail = curTail(pane); + const bare = panes.File.displayWidth(tab, name) + @as(usize, if (keep) " Keep".len else 0) + panes.File.displayWidth(tab, tail); var whole: usize = pardes.Trail.shown_steps; while (whole > 1 and rowsOf(bare + walkCells(t, whole, tab), width) > rowsOf(bare, width)) whole -= 1; - return whole; + const r = p.view().rects[id]; + const walked = t.n > @as(usize, @intFromBool(t.steps[0] == .owner)) + 1; + // A pane not laid out has no rows to cut to: one never laid out, or + // one the layout has given its width and not yet its height (the band + // host's floor, layout.floorRows, wraps its tag at rest then). + if (!keep or !walked or pane.prompt == .name or pane.collapsed or !pane.tag_expanded or r.w == 0 or r.h == 0) return .{ .whole = whole }; + // Its first line: the prefix, the space restPrefix gives a tail + // without one, the tail's first line; and the rows its others take. + const first = std.mem.indexOfScalar(u8, tail, '\n') orelse tail.len; + var below: usize = 0; + if (first < tail.len) { + var lines = std.mem.splitScalar(u8, tail[first + 1 ..], '\n'); + while (lines.next()) |line| below += rowsOf(panes.File.displayWidth(tab, line), width); + } + const gap: usize = @intFromBool(tail.len > 0 and std.mem.indexOfScalar(u8, " \t\n", tail[0]) == null); + const rest = " Keep".len + gap + panes.File.displayWidth(tab, tail[0..first]); + const path = panes.File.displayWidth(tab, name); + const rows = r.h -| layout.min_body_rows; + if (@min(rowsOf(walkCells(t, whole, tab) + path + rest, width) + below, pardes.MAX_TAG_ROWS) <= rows) return .{ .whole = whole }; + // The newest step alone, then as much of the path's end as fits, after + // a `…` cell. + const room = (rows -| below) * width; + const used = walkCells(t, 1, tab) + rest; + if (used + path <= room) return .{ .whole = 1, .squeezed = true }; + const drop = used + path + 1 - room; + const base = if (std.mem.lastIndexOfScalar(u8, name, '/')) |slash| slash + 1 else 0; + var cut: usize = 0; + var cells: usize = 0; + while (cut < base and cells < drop) { + const next = modal.nextGrapheme(name, cut); + cells += panes.File.displayWidth(tab, name[cut..next]); + cut = next; + } + return .{ .whole = 1, .cut = @min(cut, base), .squeezed = true }; } /// The cells a walk's words take at rest with its newest `whole` back @@ -241,10 +297,11 @@ fn rowsOf(cells: usize, width: usize) usize { pub fn forwardSpan(p: *const Pardes, pane: *const Pane) [2]usize { const f = pane.file orelse return .{ 0, 0 }; if (pane.trail.n == 0 or pardes.Trail.outOfRest(p, pane)) return .{ 0, 0 }; - const whole = folded(p, pane); + const fold = folded(p, pane); const name = if (pane.prompt == .name) pane.input.own orelse f.path else f.path; - const lo = pane.trail.bytes(.back, whole) + name.len; - return .{ lo, lo + pane.trail.bytes(.forward, whole) }; + const dots: usize = if (fold.cut > 0) "…".len else 0; + const lo = pane.trail.bytes(.back, fold.whole) + dots + name.len - fold.cut; + return .{ lo, lo + pane.trail.bytes(.forward, fold.whole) }; } /// The step of pane `pane`'s walk whose word is at byte `at` of its tag's @@ -252,7 +309,7 @@ pub fn forwardSpan(p: *const Pardes, pane: *const Pane) [2]usize { pub fn trailAt(p: *const Pardes, pane: *const Pane, at: usize) ?u8 { if (pane.trail.n == 0 or pane.file == null) return null; if (pardes.Trail.outOfRest(p, pane)) return pane.trail.stepAt(.newest, 1, at); - const whole = folded(p, pane); + const whole = folded(p, pane).whole; const ahead = forwardSpan(p, pane); if (at < nameAt(p, pane)) return pane.trail.stepAt(.back, whole, at); if (at >= ahead[0] and at < ahead[1]) return pane.trail.stepAt(.forward, whole, at - ahead[0]); @@ -477,10 +534,14 @@ pub fn onName(p: *const Pardes, pane: *Pane, row: usize, col: usize) ?usize { const name = if (pane.prompt == .name) pane.input.own orelse f.path else f.path; var room: [pardes.Trail.max_steps * (pardes.Trail.max_text + 32)]u8 = undefined; var w: std.Io.Writer = .fixed(&room); - pane.trail.write(.back, folded(p, pane), &w) catch return null; + const fold = folded(p, pane); + pane.trail.write(.back, fold.whole, &w) catch return null; const lead = panes.File.displayWidth(tab, w.buffered()); - if (col < lead or col >= lead + panes.File.displayWidth(tab, name)) return null; - return col - lead; + // A name cut from its left (`folded`) shows a `…` cell, then its end: + // the `…` is where its end starts. + const dots: usize = @intFromBool(fold.cut > 0); + if (col < lead or col >= lead + dots + panes.File.displayWidth(tab, name[fold.cut..])) return null; + return panes.File.displayWidth(tab, name[0..fold.cut]) + ((col - lead) -| dots); } /// A key typed into a saving file's path, with the tag's cursor there, @@ -493,7 +554,10 @@ pub fn typedIntoName(p: *Pardes, pane: *Pane, key: pardes.Key) bool { // The name starts after its walk's words. const col: usize = @intCast(@max(0, pane.tag.cur_col)); if (col < nameAt(p, pane)) return false; - const at = col - nameAt(p, pane); + // In a name cut from its left (`folded`), its end after the `…`. + const cut = folded(p, pane).cut; + const dots: usize = if (cut > 0) "…".len else 0; + const at = cut + ((col - nameAt(p, pane)) -| dots); const back = key.cp == pardes.Key.backspace or pardes.hit(key, config.insert_backspace_alias); const forward = key.cp == pardes.Key.delete or pardes.hit(key, config.insert_delete_alias); const typed = key.text.len > 0 and !key.ctrl and !key.alt; |
