summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-25 14:56:11 -0300
committerGabriel Schneider <[email protected]>2026-11-25 15:00:10 -0300
commit98872935ca6ea4e602fd5bfc3948f9bbe77a3ba3 (patch)
tree3270eda78534bc6caf3512cc269b3e39b6676e7a /core
parentc6dc2a6148855e0f02e86103dd80f47525a985e4 (diff)
parented518c211808ebee46f934320569d86121a8a739 (diff)
downloadpardes-98872935ca6ea4e602fd5bfc3948f9bbe77a3ba3.tar.gz
pardes-98872935ca6ea4e602fd5bfc3948f9bbe77a3ba3.zip
walk UI M11: Z1's three changes (nqultymy TagState.loaded holds a loaded tag state to what its own state reads, the dump fuzz seeding describe-key's state too; rllrtrxu R's two nits; xxmkroru ed518c211808 a Messages picker's keys are SPC h's, so Backspace on its empty field no longer kills the session) merged onto M10 (lkswuzxk), resolved by meaning: two text conflicts, both the tests the two lines put at the end of the same file (core/Pick.zig: F1's "a picker previews the row under its cursor from the frame its rows come ..." and Z1's "Backspace on a Messages picker's empty field ..."; core/TagState.zig: F1's "a rolled level that wraps has its hints on its last row ..." and Z1's two load tests), each kept whole, F1's first; the rest sits apart (F1's TagState.head and Pick.preview against Z1's TagState.loaded and Pick.words; F1 adds no field to a dump, so loaded's checks read the same state); the tree after the merge is M10's with exactly Z1's diff from M9 (5 files, +274 -20); core-test 1105/1276 (171 skipped: M10's 1102 + Z1's three), load 3 to 5
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/Pick.zig25
-rw-r--r--core/TagState.zig247
-rw-r--r--core/Trail.zig10
-rw-r--r--core/bindings.zig2
-rw-r--r--core/fuzz.zig10
5 files changed, 274 insertions, 20 deletions
diff --git a/core/Pick.zig b/core/Pick.zig
index 3e326bb4..b76020ca 100644
--- a/core/Pick.zig
+++ b/core/Pick.zig
@@ -57,8 +57,9 @@ const Key = pardes.Key;
/// (SPC l a, the body showing the one under the cursor as its edit).
pub const Source = enum { find, grep, recent, panes, symbols, all, jumplist, list, messages, themes, actions };
-/// Each source's word in the tag and the leader keys of the builtin that
-/// opens it, its key cells (`␣ f Find`).
+/// Each source's word in the tag and its key cells (`␣ f Find`); a
+/// source whose Backspace leaves it (`back`) goes back to the SPC level of
+/// those keys: a group's.
const words = std.EnumArray(Source, struct { word: []const u8, keys: []const u8 }).init(.{
.find = .{ .word = "Find", .keys = "f" },
.grep = .{ .word = "Grep", .keys = "f" },
@@ -68,7 +69,7 @@ const words = std.EnumArray(Source, struct { word: []const u8, keys: []const u8
.all = .{ .word = "All", .keys = "" },
.jumplist = .{ .word = "Jumplist", .keys = "j" },
.list = .{ .word = "List", .keys = "l" },
- .messages = .{ .word = "Messages", .keys = "hm" },
+ .messages = .{ .word = "Messages", .keys = "h" },
.themes = .{ .word = "Themes", .keys = "t" },
.actions = .{ .word = "Actions", .keys = "la" },
});
@@ -2601,3 +2602,21 @@ test "a picker previews the row under its cursor from the frame its rows come, w
try std.testing.expectEqualStrings(a_path, p.panes[greader].?.file.?.path);
try std.testing.expectEqual(@as(?usize, 1), landingLine(p, frame.allocator(), p.panes[greader].?));
}
+
+test "Backspace on a Messages picker's empty field goes back to the level it was run from, SPC h, unrolled and drawn: its keys are its level's, as every other picker's are" {
+ const Key_ = pardes.Key;
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 40 });
+ defer p.deinit();
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ _ = try p.setTestFile("one\ntwo\n");
+ for (" hm") |c| p.update(.{ .key = .{ .cp = c } });
+ try std.testing.expectEqual(Source.messages, live(p).?.source);
+ p.sync();
+ _ = try p.render(frame.allocator());
+ p.update(.{ .key = .{ .cp = Key_.backspace } });
+ try std.testing.expect(p.view().prefix == .leader and p.view().tag_state.unrolled);
+ try std.testing.expectEqualStrings("h", p.view().leader_keys[0..p.view().leader_n]);
+ p.sync();
+ _ = try p.render(frame.allocator());
+}
diff --git a/core/TagState.zig b/core/TagState.zig
index e8ba816e..1e8b4dea 100644
--- a/core/TagState.zig
+++ b/core/TagState.zig
@@ -268,23 +268,71 @@ pub fn wake(p: *const Pardes) ?u64 {
return soonest;
}
-/// Each view's tag state as a dump gave it, held to what it indexes: Help's
-/// hits in the tree and the registry, its rows' cursor in them, the field's
-/// caret in its text, describe-key's found leaf or struck key in its keys.
-/// One that is not (a damaged dump: the fuzz's cut and flipped bytes) is
-/// at rest, its memory of leaves kept (dump.zig afterLoad).
+/// Each view's tag state as a dump gave it, held to what its state reads
+/// (dump.zig afterLoad); one that is not (a damaged dump: the fuzz's cut
+/// and flipped bytes) is at rest, its memory of leaves kept. Each state's
+/// own fields alone: what another state left in it (describe-key's `found`
+/// under Help, a picker's cursor past Help's rows) is as the session has
+/// it, and so is its digest. Every state: the field's caret in its text, a
+/// struck key a cell (keyName's table). Help: its hits leaves of the tree
+/// or SPC words of the registry, its cursor in them, its scope what `?` was
+/// struck under (SPC's keys to a group, as many as SPC's path holds: its
+/// Backspace unrolls them, keys.helpBack; else none). describe-key: its
+/// keys cells; found, a root's keys to a leaf, whose level Band.of
+/// replays; with no root, nothing typed or the one key struck. A picker:
+/// its cursor in its rows (Pick.rowAt; All's are found again at each
+/// read). And the view's SPC keys, every level's path (`current`): cells
+/// to a group, else the view is out of SPC too.
pub fn loaded(p: *Pardes) void {
for (&p.views) |*slot| if (slot.*) |*v| {
const s = &v.tag_state;
- var held = s.field.caret <= s.field.len and s.nhits <= max_hits and s.rows.at < @max(1, s.nhits) and !(s.found and s.scope_n == 0) and !(s.missed and s.scope_root == null and s.scope_n == 0);
- // `:`'s hits index its own rows (the themes, the settings: Command.zig,
- // which holds each where it reads it); the rest the tree's leaves.
- const command = s.kind == .prompt and s.prompt.op == .command;
- for (s.hits[0..@min(s.nhits, max_hits)]) |at| held = held and (command or at < bindings.flat.len + p.kinds.nwords);
+ const keys = s.scope[0..s.scope_n];
+ var held = s.field.caret <= s.field.len and s.nhits <= max_hits and (s.miss == 0 or cells(&.{s.miss}));
+ switch (s.kind) {
+ .help => {
+ for (s.hits[0..@min(s.nhits, max_hits)]) |at| held = held and (at < bindings.flat.len or at - bindings.flat.len < p.kinds.nwords and p.kinds.words[at - bindings.flat.len].leader.len > 0);
+ held = held and s.rows.at < @max(1, s.nhits) and
+ if (s.scope_root == .leader) keys.len <= v.leader_keys.len and cells(keys) and reaches(p, .leader, keys, false) else keys.len == 0;
+ },
+ .describe => held = held and cells(keys) and !(s.found and s.missed) and if (s.scope_root) |r|
+ r != .register and (!s.found or keys.len > 0 and reaches(p, r, keys, true))
+ else
+ !s.found and keys.len == @intFromBool(s.missed),
+ .pick => if (@import("Pick.zig").byId(p, s.pick)) |pk| {
+ held = held and (pk.source == .all or s.rows.at < @max(1, @import("Pick.zig").count(p, pk)));
+ },
+ .rest, .prompt, .rename => {},
+ }
+ const spc = v.leader_keys[0..v.leader_n];
+ if (v.prefix == .leader and !(cells(spc) and reaches(p, .leader, spc, false))) {
+ v.prefix = .none;
+ v.leader_n = 0;
+ held = false;
+ }
if (!held) s.* = .{ .used = s.used };
};
}
+/// Whether each of `keys` is a cell keyName names.
+fn cells(keys: []const u8) bool {
+ for (keys) |k| if (k < ' ' or k > '~') return false;
+ return true;
+}
+
+/// Whether `path` under `root` is a group (`leaf` false) or a leaf of the
+/// tree or of the registry's SPC words. Every builtin's, whichever view's
+/// frontend took it (bindings.level drops the live view's others): a load
+/// holds each view the same in every process.
+fn reaches(p: *const Pardes, root: Root, path: []const u8, leaf: bool) bool {
+ if (bindings.nodeAt(root, path)) |n| if (if (leaf) n.leaf != null else n.children.len > 0) return true;
+ if (root != .leader) return false;
+ for (p.kinds.words[0..p.kinds.nwords]) |*w| {
+ const keys = w.leader.slice();
+ if (if (leaf) std.mem.eql(u8, keys, path) else keys.len > path.len and std.mem.startsWith(u8, keys, path)) return true;
+ }
+ return false;
+}
+
/// Asking (SPEC §3.2, §10.2): a question waiting on the pane, its tag at
/// rest, in place of the tag's own text: what it asks, `▸`, each answer's
/// key and word, and how to give one (`Esc later` while SPC e has given it
@@ -1390,3 +1438,182 @@ test "a rolled level that wraps has its hints on its last row at every width tha
try std.testing.expect(hostOf(p) == null);
};
}
+
+test "a dump holding describe-key's state, or Help's, or a level's, damaged where a draw or a key indexes it, loads to rest and draws and takes keys" {
+ const Key = pardes.Key;
+ const gpa = std.testing.allocator;
+ const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 120, .rows = 40 });
+ defer p.deinit();
+ _ = try p.setTestFile("one\ntwo\nthree\n");
+ p.clock.now_ns = 5 * std.time.ns_per_s;
+ p.clock.stepped_ns = p.clock.now_ns;
+ const typed = struct {
+ fn keys(q: *Pardes, cps: []const u8) void {
+ for (cps) |c| q.update(.{ .key = .{ .cp = c } });
+ }
+ }.keys;
+ // Each case: the state a session made (describe-key's `g d` found,
+ // Help under `SPC t`, SPC's level rolled), then a field of it as a cut
+ // or flipped dump gives it.
+ const Case = struct { keys: []const u8, damage: *const fn (v: *View) void };
+ const cases = [_]Case{
+ // Found with no root (Band.takes, Band.of: `scope_root.?`).
+ .{ .keys = " hkgd", .damage = struct {
+ fn f(v: *View) void {
+ v.tag_state.scope_root = null;
+ }
+ }.f },
+ // Found on keys no leaf of the tree is: `SPC z z` (its level
+ // empty, Band.of's `level[at]`), `SPC t` (a group), `g z` (none).
+ .{ .keys = " hkgd", .damage = struct {
+ fn f(v: *View) void {
+ v.tag_state.scope_root = .leader;
+ v.tag_state.scope[0..2].* = "zz".*;
+ v.tag_state.scope_n = 2;
+ }
+ }.f },
+ .{ .keys = " hkgd", .damage = struct {
+ fn f(v: *View) void {
+ v.tag_state.scope_root = .leader;
+ v.tag_state.scope[0] = 't';
+ }
+ }.f },
+ .{ .keys = " hkgd", .damage = struct {
+ fn f(v: *View) void {
+ v.tag_state.scope[0] = 'z';
+ }
+ }.f },
+ // Found and missed at once; a register's root, which describe-key
+ // never takes.
+ .{ .keys = " hkgd", .damage = struct {
+ fn f(v: *View) void {
+ v.tag_state.missed = true;
+ }
+ }.f },
+ .{ .keys = " hkgd", .damage = struct {
+ fn f(v: *View) void {
+ v.tag_state.scope_root = .register;
+ }
+ }.f },
+ // A struck key past keyName's table, with no root (`s.scope[0]`)
+ // and under one (bindings.chord).
+ .{ .keys = " hkq", .damage = struct {
+ fn f(v: *View) void {
+ v.tag_state.scope[0] = 0x01;
+ }
+ }.f },
+ .{ .keys = " hkgq", .damage = struct {
+ fn f(v: *View) void {
+ v.tag_state.scope[0] = 0x7f;
+ }
+ }.f },
+ // Help's scope: more keys than SPC's path holds (Backspace copies
+ // them into it: keys.helpBack), keys to no group (Backspace unrolls
+ // their level), a key past keyName's table (its key cells).
+ .{ .keys = " t?", .damage = struct {
+ fn f(v: *View) void {
+ v.tag_state.scope[0..6].* = "tttttt".*;
+ v.tag_state.scope_n = 6;
+ }
+ }.f },
+ .{ .keys = " t?", .damage = struct {
+ fn f(v: *View) void {
+ v.tag_state.scope[0..2].* = "zz".*;
+ v.tag_state.scope_n = 2;
+ }
+ }.f },
+ .{ .keys = " t?", .damage = struct {
+ fn f(v: *View) void {
+ v.tag_state.scope[0] = 0x01;
+ }
+ }.f },
+ // SPC's level rolled and shown: a struck key past keyName's table
+ // (`s.miss`); unrolled on SPC keys to no group (Band.of's
+ // `level[at]`); SPC's keys past the table (their cells, the chord).
+ .{ .keys = " ", .damage = struct {
+ fn f(v: *View) void {
+ v.tag_state.due_ns = 1;
+ v.tag_state.miss = 0x05;
+ }
+ }.f },
+ .{ .keys = " ", .damage = struct {
+ fn f(v: *View) void {
+ v.leader_keys[0..2].* = "zz".*;
+ v.leader_n = 2;
+ v.tag_state.unrolled = true;
+ }
+ }.f },
+ .{ .keys = " ", .damage = struct {
+ fn f(v: *View) void {
+ v.leader_keys[0] = 0x01;
+ v.leader_n = 1;
+ v.tag_state.due_ns = 1;
+ }
+ }.f },
+ };
+ for (cases) |case| {
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ typed(p, case.keys);
+ try std.testing.expect(p.view().tag_state.kind != .rest or p.view().prefix == .leader);
+ case.damage(p.view());
+ const bytes = try pardes.dump.byteDump(p);
+ defer gpa.free(bytes);
+ // The session itself at rest again: the damage is the dump's.
+ p.view().tag_state = .{};
+ p.view().prefix = .none;
+ p.view().leader_n = 0;
+ var notes: std.ArrayList(u8) = .empty;
+ defer notes.deinit(gpa);
+ const q = try pardes.dump.load(gpa, .{ .cols = 120, .rows = 40 }, bytes, &notes);
+ defer q.deinit();
+ const s = &q.view().tag_state;
+ try std.testing.expect(s.kind == .rest and s.root == null and !s.unrolled and s.miss == 0);
+ // SPC's own keys kept only where they reach a group: none here.
+ try std.testing.expect(q.view().prefix != .leader or q.view().leader_n == 0);
+ // Drawn, then keys a state reads (Enter, Backspace, Down), drawn.
+ q.clock.now_ns = 10 * std.time.ns_per_s;
+ var frame = std.heap.ArenaAllocator.init(gpa);
+ defer frame.deinit();
+ q.sync();
+ _ = try q.render(frame.allocator());
+ for ([_]u21{ Key.backspace, Key.down, Key.enter, Key.backspace }) |cp| {
+ q.update(.{ .key = .{ .cp = cp } });
+ q.sync();
+ _ = try q.render(frame.allocator());
+ }
+ }
+}
+
+test "a tag state a session made loads as it was, its digest the session's: Help after describe-key found a leaf, a picker's cursor past Help's rows" {
+ const Key = pardes.Key;
+ const gpa = std.testing.allocator;
+ const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 120, .rows = 40 });
+ defer p.deinit();
+ _ = try p.setTestFile("one\ntwo\nthree\n");
+ const same = struct {
+ fn digest(q: *Pardes) !void {
+ const bytes = try pardes.dump.byteDump(q);
+ defer std.testing.allocator.free(bytes);
+ const r = try pardes.dump.load(std.testing.allocator, .{ .cols = 120, .rows = 40 }, bytes, null);
+ defer r.deinit();
+ try std.testing.expectEqual(q.view().tag_state.kind, r.view().tag_state.kind);
+ try std.testing.expectEqual(q.view().tag_state.rows.at, r.view().tag_state.rows.at);
+ try std.testing.expectEqual(pardes.tape.digestOf(q), pardes.tape.digestOf(r));
+ }
+ }.digest;
+ // A picker of three rows, its cursor on the third (Help never opened:
+ // no hits), then rolled up.
+ pardes.Pick.open(p, 0, .list, "Refs", "", "a\nb\nc\n");
+ for (0..2) |_| p.update(.{ .key = .{ .cp = Key.down } });
+ try std.testing.expect(p.view().tag_state.kind == .pick and p.view().tag_state.rows.at == 2);
+ try same(p);
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ try same(p);
+ // describe-key's `g d` found, then Help over every root: `found` is
+ // describe-key's alone, left as it was.
+ for (" hkgd") |c| p.update(.{ .key = .{ .cp = c } });
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ for (" ?") |c| p.update(.{ .key = .{ .cp = c } });
+ try std.testing.expect(p.view().tag_state.kind == .help and p.view().tag_state.found);
+ try same(p);
+}
diff --git a/core/Trail.zig b/core/Trail.zig
index ddc350ca..73ea1ffb 100644
--- a/core/Trail.zig
+++ b/core/Trail.zig
@@ -55,13 +55,13 @@ pub const Step = union(enum) {
/// the first step.
owner: u32,
/// A list the pane came through (`Find pick 3/6 •2`, §5.6): its word
- /// and the pickers' index for it. Made by the pickers (not yet).
+ /// and the pickers' index for it. Made as a picker lands (Pick.listed).
list: Word,
- /// A search made in the pane (`/dirty/ 3/7`, §7.3). Made by the
- /// prompts (not yet).
+ /// A search made in the pane (`/dirty/ 3/7`, §7.3). Made by a search
+ /// prompt (Prompt.word).
search: Word,
- /// A chain of selection prompts as an Edit line (§7.5). Made by the
- /// prompts (not yet).
+ /// A chain of selection prompts as an Edit line (§7.5). Made by the sam
+ /// prompts (Prompt.link).
recipe: Word,
};
pub const Place = struct { path: Kind.Buf(max_text) = .{}, line: u32 = 0, col: u32 = 0 };
diff --git a/core/bindings.zig b/core/bindings.zig
index a8b81842..ab00c1da 100644
--- a/core/bindings.zig
+++ b/core/bindings.zig
@@ -582,7 +582,7 @@ test "\" shows the registers rolled, the ones holding something, each its value
try p.registers.put(p.gpa, 'a', "const best = rank(q, name) orelse continue;\nreturn best;", 0, 1, true);
try p.registers.put(p.gpa, '"', "self.dirty = true;", 0, 1, true);
try p.registers.put(p.gpa, 'n', "ab\ncd", 0, 1, true);
- try p.registers.put(p.gpa, 'p', "/tmp/claude-1000/wuS/r/proj/core/Query.zig", 0, 1, true);
+ try p.registers.put(p.gpa, 'p', "/home/user/proj/core/Query.zig", 0, 1, true);
var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
defer frame.deinit();
const a = frame.allocator();
diff --git a/core/fuzz.zig b/core/fuzz.zig
index 091eca63..56ded66b 100644
--- a/core/fuzz.zig
+++ b/core/fuzz.zig
@@ -803,6 +803,14 @@ test "a dump and an image cut, flipped and grown: refused or loaded, never a pan
defer gpa.free(bytes);
const image = try pardes.dump.dumpBytes(p);
defer gpa.free(image);
+ // And one with describe-key's state (SPC h k, `g d` found: a root, its
+ // keys, the leaf whose level the band replays), Help's fields as Help
+ // left them.
+ p.update(.{ .key = .{ .cp = pardes.Key.escape } });
+ for (" hkgd") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } });
+ try testing.expect(p.view().tag_state.kind == .describe and p.view().tag_state.found);
+ const described = try pardes.dump.byteDump(p);
+ defer gpa.free(described);
// Seconds a road, each core used (`use`). The image's past 1779 seeds
// reach xitdb's own reader (a slot's tag past its kinds: a `switch` on
// it), a dependency's.
@@ -816,7 +824,7 @@ test "a dump and an image cut, flipped and grown: refused or loaded, never a pan
// `live` (the core read in place, its own `live` undefined), a live
// message's `src` length 0xAAAA when the digest walked it.
try loadSeed(bytes, .join, 6356);
- for ([_][]const u8{ bytes, image }, [_]Road{ .join, .restore }, [_]u64{ 2048, 1024 }) |whole, road, n| {
+ for ([_][]const u8{ bytes, described, image }, [_]Road{ .join, .join, .restore }, [_]u64{ 2048, 2048, 1024 }) |whole, road, n| {
try loadSeed(whole, road, 0);
for (1..n + 1) |seed| try loadSeed(whole, road, seed);
}