summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-24 22:32:25 -0300
committerGabriel Schneider <[email protected]>2026-11-24 22:32:25 -0300
commit791d47a64db09f842d23b3d0b03c40951f30aae6 (patch)
treed2d8b9fa92055748d866d9296b26ae995df59172
parent89b3e7365bac28c4cd7d52d40c1786c01db5af52 (diff)
downloadpardes-791d47a64db09f842d23b3d0b03c40951f30aae6.tar.gz
pardes-791d47a64db09f842d23b3d0b03c40951f30aae6.zip
walk: Enter on a word of the walk with the keyboard in the tag Looks it as a click does (Tab Execs it, as B2), and out of rest the walk folds to its newest word, its older ones `·` (pick-ui SPEC §6.3, §3.4.3, walk UI line F item 5, the gaps line B left): keys.zig handleKey's Enter-in-a-tag asks tagline.trailAt at the cursor's byte before taking the word as a builtin's operand, the keyboard back in the body as a click leaves it; Trail.folded says how many back steps a tag writes whole (shown_steps at rest, one while TagState.hostOf is its pane), which Trail.write, bytes and stepAt now take (wordOf's fold the caller's), so the name's offset (tagline.nameAt), the forward span, a click on a step, the drafted name and the name's tint all read the trail as it is drawn (nameAt, forwardSpan, onName and draw.tagTintRange take the session); TEST: Trail.zig "Enter on a word of the walk, the keyboard in the tag, goes back to its step ..." (SPC folds `‹@pN › · › rank.zig:20 ›`, Esc unfolds, Enter on rank.zig:10 goes back there); core-test 1026/1193 (167 skipped), 0 failed, load 8
Co-Authored-By: Claude Opus 5.5 <[email protected]>
-rw-r--r--core/Trail.zig61
-rw-r--r--core/draw.zig10
-rw-r--r--core/keys.zig7
-rw-r--r--core/mouse.zig2
-rw-r--r--core/tagline.zig46
5 files changed, 91 insertions, 35 deletions
diff --git a/core/Trail.zig b/core/Trail.zig
index b5dff554..571779b4 100644
--- a/core/Trail.zig
+++ b/core/Trail.zig
@@ -18,6 +18,7 @@ const look = @import("look.zig");
const Pardes = pardes.Pardes;
const Pane = panes.Pane;
const Spot = look.Spot;
+const TagState = @import("TagState.zig");
const Trail = @This();
@@ -275,9 +276,9 @@ pub const Part = enum { back, forward };
/// Step `i`'s word: `‹@p3`, `rank.zig:14`, a list's, search's or recipe's
/// own text; `·` when it is folded.
-fn wordOf(t: *const Trail, i: usize, buf: *[max_text + 16]u8) []const u8 {
+fn wordOf(t: *const Trail, i: usize, whole: usize, buf: *[max_text + 16]u8) []const u8 {
const s = t.steps[i];
- if (s != .owner and i < t.cur and t.cur - i > shown_steps) return "·";
+ if (s != .owner and i < t.cur and t.cur - i > whole) return "·";
// The step's own bytes, not a copy's (a copy is gone at the return).
return switch (t.steps[i]) {
.owner => |serial| std.fmt.bufPrint(buf, "‹" ++ config.pane_addr ++ "{d}", .{serial}) catch unreachable, // a u32 fits
@@ -297,34 +298,43 @@ fn range(t: *const Trail, part: Part) [2]usize {
}
/// The back steps' words, each with the separator after it (before the
-/// path), or the forward steps', each with one before it (after the path).
-pub fn write(t: *const Trail, part: Part, w: *std.Io.Writer) std.Io.Writer.Error!void {
+/// path), or the forward steps', each with one before it (after the path):
+/// the newest `whole` back steps whole, older ones `·` (`folded`).
+pub fn write(t: *const Trail, part: Part, whole: usize, w: *std.Io.Writer) std.Io.Writer.Error!void {
var buf: [max_text + 16]u8 = undefined;
const r = range(t, part);
for (r[0]..r[1]) |i| switch (part) {
- .back => try w.print("{s}" ++ sep, .{wordOf(t, i, &buf)}),
- .forward => try w.print(sep ++ "{s}", .{wordOf(t, i, &buf)}),
+ .back => try w.print("{s}" ++ sep, .{wordOf(t, i, whole, &buf)}),
+ .forward => try w.print(sep ++ "{s}", .{wordOf(t, i, whole, &buf)}),
};
}
/// The bytes `write` writes for `part`.
-pub fn bytes(t: *const Trail, part: Part) usize {
+pub fn bytes(t: *const Trail, part: Part, whole: usize) usize {
var buf: [max_text + 16]u8 = undefined;
var n: usize = 0;
const r = range(t, part);
- for (r[0]..r[1]) |i| n += wordOf(t, i, &buf).len + sep.len;
+ for (r[0]..r[1]) |i| n += wordOf(t, i, whole, &buf).len + sep.len;
return n;
}
+/// The back steps pane `pane`'s tag writes whole: `shown_steps` at rest,
+/// the newest alone while its tag is out of rest (SPEC §3.4.3), so a
+/// state's head and the band's spines keep their room.
+pub fn folded(p: *const Pardes, pane: *const Pane) usize {
+ const host = TagState.hostOf(p) orelse return shown_steps;
+ return if (p.panes[host] == pane) 1 else shown_steps;
+}
+
/// The step whose word in `part` is at byte `off` of what `write` wrote
/// for it, null on a separator or past them.
-pub fn stepAt(t: *const Trail, part: Part, off: usize) ?u8 {
+pub fn stepAt(t: *const Trail, part: Part, whole: usize, off: usize) ?u8 {
var buf: [max_text + 16]u8 = undefined;
var x: usize = 0;
const r = range(t, part);
for (r[0]..r[1]) |i| {
if (part == .forward) x += sep.len;
- const n = wordOf(t, i, &buf).len;
+ const n = wordOf(t, i, whole, &buf).len;
if (off >= x and off < x + n) return @intCast(i);
x += n;
if (part == .back) x += sep.len;
@@ -722,3 +732,34 @@ test "Jumps new-pane jumps as before the walk: a new pane for a file no pane sho
};
try std.testing.expectEqual(open + 2, now);
}
+
+test "Enter on a word of the walk, the keyboard in the tag, goes back to its step as a click does; out of rest the walk folds to its newest word" {
+ var f: Fixture = .{ .p = undefined, .tmp = undefined };
+ try f.init(60);
+ defer f.deinit();
+ const p = f.p;
+ const owner = p.panes[f.held].?.serial;
+ for ([_]usize{ 10, 20, 30 }) |line| f.look(f.held, "rank.zig", line);
+ const r = p.view().active;
+ const pane = p.panes[r].?;
+ var buf: [4096 + 128]u8 = undefined;
+ var at: [64]u8 = undefined;
+ const rest = try std.fmt.bufPrint(&buf, "‹@p{d} › rank.zig:10 › rank.zig:20 › {s}/rank.zig Keep", .{ owner, f.dir });
+ try std.testing.expect(std.mem.startsWith(u8, try tagOf(p, pane), rest));
+ // SPC: out of rest, the older steps are `·`, the owner and the newest
+ // whole; back at rest, as they were.
+ p.update(.{ .key = .{ .cp = ' ' } });
+ var folded_buf: [4096 + 128]u8 = undefined;
+ try std.testing.expect(std.mem.startsWith(u8, try tagOf(p, pane), try std.fmt.bufPrint(&folded_buf, "‹@p{d} › · › rank.zig:20 › {s}/rank.zig", .{ owner, f.dir })));
+ p.update(.{ .key = .{ .cp = pardes.Key.escape } });
+ try std.testing.expect(std.mem.startsWith(u8, try tagOf(p, pane), rest));
+ // The keyboard in the tag, its cursor on `rank.zig:10`: Enter goes back
+ // to that step, the keyboard in the body again.
+ pane.focus = .tag;
+ pane.tag.cur_row = 0;
+ pane.tag.cur_col = @intCast(std.mem.indexOf(u8, rest, "rank.zig:10").? + 2);
+ p.update(.{ .key = .{ .cp = pardes.Key.enter } });
+ p.sync();
+ try std.testing.expectEqualStrings("rank.zig:10", f.at(&at));
+ try std.testing.expect(pane.focus == .body);
+}
diff --git a/core/draw.zig b/core/draw.zig
index 5282b1c9..cf62adf8 100644
--- a/core/draw.zig
+++ b/core/draw.zig
@@ -631,7 +631,7 @@ fn joinCells(s: *Surface, x: u16, y: u16, cells: []const Cell, from: usize, w: u
if (!cells[from].default and cells[from].len == 0) blank(&row[x], ink);
}
-fn tagTintRange(pane: *const Pane, tag: []const u8, prefix_len: usize) ?struct { lo: usize, hi: usize } {
+fn tagTintRange(p: *const Pardes, pane: *const Pane, tag: []const u8, prefix_len: usize) ?struct { lo: usize, hi: usize } {
if (pane.isTerminal()) {
// `tag` is the first row; a prefix longer than it ran to a second.
var words = std.mem.tokenizeAny(u8, tag[@min(prefix_len, tag.len)..], " \t\r\n");
@@ -642,7 +642,7 @@ fn tagTintRange(pane: *const Pane, tag: []const u8, prefix_len: usize) ?struct {
}
return null;
}
- var start: usize = tagline.nameAt(pane);
+ var start: usize = tagline.nameAt(p, pane);
const name = if (pane.file) |file|
if (pane.prompt == .name) pane.input.own orelse file.path else file.path
else if (pane.addon) |k| blk: {
@@ -955,7 +955,7 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
else if (pane.prompt == .name) caret: {
// A drafted name is the prefix: its caret is on row 0 of the tag,
// the rows it wrapped onto included.
- const at = modal.positionAt(shown.text, shown.fromReal(tagline.nameAt(pane) + @as(usize, @intCast(@max(0, pane.input.cur_col)))));
+ const at = modal.positionAt(shown.text, shown.fromReal(tagline.nameAt(p, pane) + @as(usize, @intCast(@max(0, pane.input.cur_col)))));
if (at.row < top or at.row >= top + rows) break :caret null;
break :caret .{ .row = at.row - top, .at = @min(lines[at.row - top].len, at.col) };
} else if (pane.focus == .tag and pane.prompt == .none and head == null) caret: {
@@ -975,10 +975,10 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
// The name's tint, in the tag's first line, over whichever rows it
// wrapped onto.
const first_line = whole[0 .. std.mem.indexOfScalar(u8, whole, '\n') orelse whole.len];
- if (tagTintRange(pane, first_line, prefix_len)) |name| if (name.lo < name.hi)
+ if (tagTintRange(p, pane, first_line, prefix_len)) |name| if (name.lo < name.hi)
inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, name.lo, @min(name.hi, first_line.len), if (active) chrome.tag_active_name_fg else chrome.tag_name_fg);
// A walk's forward steps, after the name, dimmed (Trail.zig).
- const ahead = tagline.forwardSpan(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), chrome.lineno);
// The head's keys in the key ink, its dimmed, underlined and struck
// words (TagState.Span), over whichever rows they wrapped onto.
diff --git a/core/keys.zig b/core/keys.zig
index 78f45820..651d6417 100644
--- a/core/keys.zig
+++ b/core/keys.zig
@@ -401,6 +401,13 @@ pub fn handleKey(p: *Pardes, key: Key) void {
break :word .{ b.lo, b.hi };
};
const txt = shown[span[0]..span[1]];
+ // On a word of the pane's walk, the step's Look or Exec, as a
+ // click there (SPEC §6.3).
+ if (header == null and t.what == .tag) if (tagline.trailAt(p, pane, modal.selectionCursor(shown, range))) |step| {
+ pane.focus = .body;
+ if (cmd == config.look_cmd) pardes.Trail.lookStep(p, p.view().active, step) else pardes.Trail.execStep(p, p.view().active, step);
+ return;
+ };
// A column tag's command acts on that column, empty or not.
p.exec_column = if (header != null) p.headerColumn() else null;
defer p.exec_column = null;
diff --git a/core/mouse.zig b/core/mouse.zig
index 400d020b..48546c12 100644
--- a/core/mouse.zig
+++ b/core/mouse.zig
@@ -1265,7 +1265,7 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void {
// (pick-ui SPEC §6.3): the one place B1 does more than
// select.
if (!dragged and tagline.trailClick(p, s.id, row, col, false)) return;
- if (if (dragged) null else tagline.onName(p.settings.tab, pane, row, col)) |at| {
+ if (if (dragged) null else tagline.onName(p, pane, row, col)) |at| {
tagline.draftName(p, pane, at);
} else if (tagline.tagOffsetAt(p, pane, row, col)) |cursor| {
pane.tag.cur_row = @intCast(cursor.row);
diff --git a/core/tagline.zig b/core/tagline.zig
index 78d5a256..e95d68de 100644
--- a/core/tagline.zig
+++ b/core/tagline.zig
@@ -163,11 +163,12 @@ pub fn pathPrefix(p: *const Pardes, arena: std.mem.Allocator, pane: *Pane) ![]co
// Its walk's back steps before the name, its forward steps after
// it (Trail.zig), in the room `bytes` measures them.
const keep_word = if (keep) " Keep" else "";
- const room = try arena.alloc(u8, pane.trail.bytes(.back) + name.len + pane.trail.bytes(.forward) + keep_word.len);
+ const whole = pardes.Trail.folded(p, pane);
+ const room = try arena.alloc(u8, pane.trail.bytes(.back, whole) + name.len + pane.trail.bytes(.forward, whole) + keep_word.len);
var w: std.Io.Writer = .fixed(room);
- pane.trail.write(.back, &w) catch return error.OutOfMemory;
+ pane.trail.write(.back, whole, &w) catch return error.OutOfMemory;
w.writeAll(name) catch return error.OutOfMemory;
- pane.trail.write(.forward, &w) catch return error.OutOfMemory;
+ pane.trail.write(.forward, whole, &w) catch return error.OutOfMemory;
w.writeAll(keep_word) catch return error.OutOfMemory;
return w.buffered();
}
@@ -183,17 +184,29 @@ pub fn pathPrefix(p: *const Pardes, arena: std.mem.Allocator, pane: *Pane) ![]co
}
/// Where a file's name starts in its tag: after its walk's back steps.
-pub fn nameAt(pane: *const Pane) usize {
- return if (pane.file != null and pane.trail.n > 0) pane.trail.bytes(.back) else 0;
+pub fn nameAt(p: *const Pardes, pane: *const Pane) usize {
+ return if (pane.file != null and pane.trail.n > 0) pane.trail.bytes(.back, pardes.Trail.folded(p, pane)) else 0;
}
/// The bytes of a file's tag its walk's forward steps take, after its name.
-pub fn forwardSpan(pane: *const Pane) [2]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) return .{ 0, 0 };
+ const whole = pardes.Trail.folded(p, pane);
const name = if (pane.prompt == .name) pane.input.own orelse f.path else f.path;
- const lo = pane.trail.bytes(.back) + name.len;
- return .{ lo, lo + pane.trail.bytes(.forward) };
+ const lo = pane.trail.bytes(.back, whole) + name.len;
+ return .{ lo, lo + pane.trail.bytes(.forward, whole) };
+}
+
+/// The step of pane `pane`'s walk whose word is at byte `at` of its tag's
+/// text, if one is there.
+pub fn trailAt(p: *const Pardes, pane: *const Pane, at: usize) ?u8 {
+ if (pane.trail.n == 0 or pane.file == null) return null;
+ const whole = pardes.Trail.folded(p, pane);
+ 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]);
+ return null;
}
/// A click at shown row `row`, display column `col` of pane `id`'s tag on
@@ -201,15 +214,9 @@ pub fn forwardSpan(pane: *const Pane) [2]usize {
/// (Trail.zig, pick-ui SPEC §6.3). True when it was on one.
pub fn trailClick(p: *Pardes, id: usize, row: usize, col: usize, run: bool) bool {
const pane = p.panes[id] orelse return false;
- if (pane.trail.n == 0 or pane.file == null) return false;
const at = tagOffsetAt(p, pane, row, col) orelse return false;
if (at.row != 0) return false;
- const lead = nameAt(pane);
- const ahead = forwardSpan(pane);
- const step = if (at.col < lead)
- pane.trail.stepAt(.back, at.col)
- else if (at.col >= ahead[0] and at.col < ahead[1]) pane.trail.stepAt(.forward, at.col - ahead[0]) else null;
- const i = step orelse return false;
+ const i = trailAt(p, pane, at.col) orelse return false;
if (run) pardes.Trail.execStep(p, id, i) else pardes.Trail.lookStep(p, id, i);
return true;
}
@@ -402,14 +409,15 @@ pub fn tagOffsetAt(p: *Pardes, pane: *Pane, row: usize, col: usize) ?modal.Curso
/// The display column in the name a click drafts at display column `col`
/// of the tag's shown row `row`: on a saving file's path, after its walk's
/// words; null off it.
-pub fn onName(tab: u16, pane: *Pane, row: usize, col: usize) ?usize {
+pub fn onName(p: *const Pardes, pane: *Pane, row: usize, col: usize) ?usize {
+ const tab = p.settings.tab;
if (row + pane.tag_top != 0) return null;
const f = pane.file orelse return null;
if (!panes.Output.fileTraits(f.output).saves) return null;
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, &w) catch return null;
+ pane.trail.write(.back, pardes.Trail.folded(p, pane), &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;
@@ -424,8 +432,8 @@ pub fn typedIntoName(p: *Pardes, pane: *Pane, key: pardes.Key) bool {
if (!panes.Output.fileTraits(f.output).saves or pane.tag.cur_row != 0) return false;
// The name starts after its walk's words.
const col: usize = @intCast(@max(0, pane.tag.cur_col));
- if (col < nameAt(pane)) return false;
- const at = col - nameAt(pane);
+ if (col < nameAt(p, pane)) return false;
+ const at = col - nameAt(p, pane);
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;