summaryrefslogtreecommitdiff
path: root/core/Trail.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/Trail.zig')
-rw-r--r--core/Trail.zig137
1 files changed, 134 insertions, 3 deletions
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);