summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-26 00:21:48 -0300
committerGabriel Schneider <[email protected]>2026-11-26 02:11:20 -0300
commitf6f02bab7554e50241faa1a0c81517126bd06b94 (patch)
tree21e30296d1e9a20b59ef5c66db46c6eddb30145a
parent3ace8b385e02a54830decb6aa48d1fa28d076a18 (diff)
downloadpardes-f6f02bab7554e50241faa1a0c81517126bd06b94.tar.gz
pardes-f6f02bab7554e50241faa1a0c81517126bd06b94.zip
Pick, Core, keys: SPC ' steps back through the kept pickers (UX DESIGN L'2, binding; the user liked L-b): Resume reopens the newest kept picker as before, and again as the next leader sequence after an Esc from the one it opened, nothing typed between, the one before it; Ctrl-o in a picker Resume opened steps to the next older kept one (its field, cursor and marks its own, where Resume opens them: Pick.resumeAt), Ctrl-i the next newer, each end said (`Resume: no picker before it: the last 8 are kept`, `Resume: the newest picker`); the head reads `Resume 2/5` before the picker's own word (`Resume 2/5 Find words`); the walk is `Pardes.resume_at` beside `picks` (0 for none, the newest 1): any other picker opened, reopened or landed ends it, and so does any key at rest but the leader and Resume's after it (Pick.keyAtRest, called beside Prompt.keyAtRest in keys.handleKey); the order is a picker's `used` (L': made, landed, or reopened by a walk, the newest the highest, Pick.touch), not its serial, and the picker the ring drops for a new one is the least used of them (Pick.rank: `used`, then the serial, for pickers a dump made before `used`); a list word naming a dropped picker says `walk: that list is gone: the last 8 are kept` (item L'1's walk passes it by); RUN (TEST FIRST): Pick.zig "SPC ' steps back through the kept pickers (UX L'2) ..." keeps three lists A, B, C and asks after each of SPC ', Esc SPC ', Ctrl-o, Ctrl-o (said: no picker before it), Ctrl-i, Ctrl-i, Esc j SPC ' (a key between: the newest again), Esc SPC ' the live picker and its head's `Resume k/3`, then Enter on B (the walk over, B the newest: SPC ' opens it as `1/3 B`), then Ctrl-o onto a list word whose picker is gone (said, passed by, the walk on to the first place): fails on L'1's tree at Pick.zig:2915 on the first SPC ' (expected `1/3 C`, the head has no Resume word), passes now; a user hit it whenever the picker wanted was not the last one; core-test 1126/1299 (173 skipped), shell-test 1347/1350 (3 skipped); load 3.9 to 4.6
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE
-rw-r--r--core/Core.zig4
-rw-r--r--core/Pick.zig158
-rw-r--r--core/keys.zig1
3 files changed, 154 insertions, 9 deletions
diff --git a/core/Core.zig b/core/Core.zig
index f47cc5d8..f9c4d6c9 100644
--- a/core/Core.zig
+++ b/core/Core.zig
@@ -413,6 +413,10 @@ stream: Stream = .{},
/// The pickers: the one live in a view's tag, and the last ones rolled
/// up, which their list words and Resume reopen (Pick.zig).
picks: [pardes.Pick.max_lists]?*pardes.Pick = @splat(null),
+/// The kept picker Resume shows, the newest 1 (Pick.nth), 0 for none:
+/// `SPC '` again after an Esc from it, nothing typed between, opens the
+/// one before it, and Ctrl-o and Ctrl-i in it step through them (UX L'2).
+resume_at: u8 = 0,
/// The panes' `Changes` (jj.zig): what was asked of jj, and what it
/// answered for each pane, by its serial: the session's, not a field of
/// every pane (a digest and a rollback copy walk every pane's fields at
diff --git a/core/Pick.zig b/core/Pick.zig
index c49e8682..85c16a69 100644
--- a/core/Pick.zig
+++ b/core/Pick.zig
@@ -147,6 +147,9 @@ act_at: u8 = 0,
queue: std.ArrayList(Queued) = .empty,
queue_bytes: std.ArrayList(u8) = .empty,
queue_at: u32 = 0,
+/// Where it stands among the kept pickers, the newest the highest
+/// (`touch`): Resume's order (`nth`), and the oldest goes for a new one.
+used: u32 = 0,
/// The step of its landing pane's trail a walk reopened it at (Ctrl-o,
/// UX L'1): its Ctrl-o and Ctrl-i walk on from that word, and its Enter
/// lands as that word's, the steps after it dropped.
@@ -211,6 +214,7 @@ pub fn previewing(p: *const Pardes, id: usize) bool {
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);
+ p.resume_at = 0;
const pk = make(p, source) catch |err| return p.reportError(.at(from), "pick", err);
pk.word.set(if (word.len > 0) word else words.get(source).word);
pk.keys.set(words.get(source).keys);
@@ -235,7 +239,7 @@ fn make(p: *Pardes, source: Source) !*Pick {
if (slot == null) {
// The oldest not live.
var oldest: ?usize = null;
- for (p.picks, 0..) |s, i| if (s) |pk| if (!pk.unrolled and (oldest == null or pk.id < p.picks[oldest.?].?.id)) {
+ for (p.picks, 0..) |s, i| if (s) |pk| if (!pk.unrolled and (oldest == null or rank(pk) < rank(p.picks[oldest.?].?))) {
oldest = i;
};
const i = oldest orelse return error.NoPickerSlots;
@@ -248,9 +252,46 @@ fn make(p: *Pardes, source: Source) !*Pick {
p.next_serial += 1;
pk.* = .{ .id = p.next_serial, .source = source };
p.picks[slot.?] = pk;
+ touch(p, pk);
return pk;
}
+/// Picker `pk` the newest kept (UX L': made, landed, reopened by a walk).
+fn touch(p: *Pardes, pk: *Pick) void {
+ var top: u32 = 0;
+ for (p.picks) |slot| if (slot) |o| {
+ top = @max(top, o.used);
+ };
+ pk.used = top +| 1;
+}
+
+/// Where picker `pk` stands among the kept ones, newer higher: its `used`,
+/// then its serial (pickers a dump made before `used` was kept).
+fn rank(pk: *const Pick) u64 {
+ return @as(u64, pk.used) << 32 | pk.id;
+}
+
+/// The `k`th newest kept picker, the newest 1.
+fn nth(p: *const Pardes, k: usize) ?*Pick {
+ var below: u64 = std.math.maxInt(u64);
+ var found: ?*Pick = null;
+ for (0..k) |_| {
+ found = null;
+ for (p.picks) |slot| if (slot) |pk| if (rank(pk) < below and (found == null or rank(pk) > rank(found.?))) {
+ found = pk;
+ };
+ below = rank(found orelse return null);
+ }
+ return found;
+}
+
+/// The pickers kept.
+fn nkept(p: *const Pardes) usize {
+ var n: usize = 0;
+ for (p.picks) |slot| n += @intFromBool(slot != null);
+ 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
@@ -651,6 +692,8 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head {
const text = &b.text;
// SPC's cell, then its keys': `␣ f`.
if (pk.keys.len > 0) try b.keyCells(.leader, pk.keys.slice());
+ // One Resume opened: where it stands among the kept (UX L'2).
+ if (p.resume_at != 0) try text.print(arena, "Resume {d}/{d} ", .{ p.resume_at, nkept(p) });
try text.appendSlice(arena, pk.word.slice());
try text.append(arena, ' ');
for (pk.refined[0..pk.nrefined]) |r| try text.print(arena, "{s} | ", .{r.query.slice()});
@@ -1157,6 +1200,8 @@ pub fn key(p: *Pardes, k: Key) void {
// word, the list rolled up unlanded. Ctrl-i is Tab where the terminal
// cannot tell them apart: a mark, as Tab.
if (pk.walking) |at| if (ctrl and (k.cp == 'o' or k.cp == 'i')) return walkOn(p, pk, at, if (k.cp == 'o') -1 else 1);
+ // One Resume opened: the next older or newer kept one (UX L'2).
+ if (p.resume_at != 0 and ctrl and (k.cp == 'o' or k.cp == 'i')) return resumeAt(p, p.paneBySerial(pk.owner) orelse p.view().active, if (k.cp == 'o') p.resume_at + 1 else p.resume_at - 1);
if (alt and (k.cp == Key.enter or k.cp == 'l')) {
pk.spine = .acts;
pk.act_at = 0;
@@ -1400,6 +1445,8 @@ fn land(p: *Pardes, wanted: How) void {
const picked = pickedRows(p, pk, a) catch return;
if (picked.len == 0) return;
const walking = pk.walking;
+ touch(p, pk);
+ p.resume_at = 0;
// Walk: the first now, the others queued for C-i.
pk.queue.clearRetainingCapacity();
pk.queue_bytes.clearRetainingCapacity();
@@ -1552,6 +1599,8 @@ 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.landing = pane.serial;
pk.made = false;
unroll(p, pk, pk.query.slice());
@@ -1575,19 +1624,36 @@ pub fn rerun(p: *Pardes, id: usize, index: u32) void {
open(p, id, pk.source, pk.word.slice(), query.slice(), pk.rows);
}
-/// Resume (`SPC '`): the last picker reopened as it was, from pane `from`,
-/// in the tag of the pane its Enter lands in.
+/// Resume (`SPC '`): the newest kept picker reopened as it was, from pane
+/// `from`, in the tag of the pane its Enter lands in; again after an Esc
+/// from it, nothing typed between, the one before it (UX L'2).
pub fn resumeFrom(p: *Pardes, from: usize) void {
- var newest: ?*Pick = null;
- for (p.picks) |slot| if (slot) |pk| if (newest == null or pk.id > newest.?.id) {
- newest = pk;
- };
- const pk = newest orelse return p.setMessage(.at(from), "Resume: no picker yet");
- TagState.toRest(p);
+ if (p.resume_at == 0 and nkept(p) == 0) return p.setMessage(.at(from), "Resume: no picker yet");
if (p.panes[from] == null) return;
+ resumeAt(p, from, p.resume_at + 1);
+}
+
+/// The `k`th newest kept picker reopened as it was, asked from pane
+/// `from`, in the tag of the pane its Enter lands in.
+fn resumeAt(p: *Pardes, from: usize, k: usize) void {
+ const pk = (if (k > 0) nth(p, k) else null) orelse
+ return p.setMessage(.at(from), if (k == 0) "Resume: the newest picker" else "Resume: no picker before it: the last 8 are kept");
+ TagState.toRest(p);
hostIn(p, pk, from) catch |err| return p.reportError(.at(from), "Resume", err);
unroll(p, pk, pk.query.slice());
unrollRows(p, pk);
+ p.resume_at = @intCast(k);
+}
+
+/// A key the tag at rest takes (keys.handleKey): any but the leader and
+/// Resume's after it ends a Resume walk, so that `SPC '` opens the newest
+/// again (UX L'2).
+pub fn keyAtRest(p: *Pardes, k: Key) void {
+ const v = p.view();
+ if (p.resume_at == 0) return;
+ if (v.prefix == .none and pardes.hit(k, config.leader)) return;
+ if (v.prefix == .leader and v.leader_n == 0 and !k.ctrl and !k.alt and k.cp == config.leader_path.get(.Resume).?[0]) return;
+ p.resume_at = 0;
}
/// B3 on a picker's row (mouse.zig bandPress): Enter on it.
@@ -2860,3 +2926,77 @@ test "a picker's preview starts under its band: its landing line ⌈visible/3⌉
try std.testing.expectEqual(rest, .{ pane.tag_rows, pane.rows, pane.file.?.scroll, p.bodyTop(pane, r) });
try std.testing.expect(std.mem.startsWith(u8, pane.file.?.content, "own 1\n"));
}
+
+test "SPC ' steps back through the kept pickers (UX L'2): again after an Esc, nothing typed between, the one before; Ctrl-o and Ctrl-i in it the next older and newer, its head `Resume 2/3`; a key between, the newest again; a list word naming a picker no longer kept says so and the walk passes it by" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 160, .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", "one\ntwo\n");
+ defer p.gpa.free(a_path);
+ const b_path = try testFile(p, &tmp, "base.zig", "text\n");
+ const base = try p.setTestFile("text\n");
+ p.gpa.free(base.file.?.path);
+ base.file.?.path = b_path;
+ const id = p.view().active;
+ const row = try std.fmt.allocPrint(p.gpa, "{s}:2:1 two\n", .{a_path});
+ defer p.gpa.free(row);
+ // Three lists kept, C the newest.
+ for ([_][]const u8{ "A", "B", "C" }) |word| {
+ open(p, id, .list, word, "", row);
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ }
+ try std.testing.expect(live(p) == null);
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ const Shown = struct {
+ /// The live picker's word and its head's `Resume k/N`, as `2/3 B`.
+ fn of(pp: *Pardes, a: std.mem.Allocator) ![]const u8 {
+ const pk = live(pp) orelse return "none";
+ const h = (try head(pp, a, pp.panes[pp.paneBySerial(pk.landing).?].?)).?;
+ const at = std.mem.indexOf(u8, h.text, "Resume ") orelse return pk.word.slice();
+ const end = std.mem.indexOfScalarPos(u8, h.text, at + "Resume ".len, ' ').?;
+ return std.fmt.allocPrint(a, "{s} {s}", .{ h.text[at + "Resume ".len .. end], pk.word.slice() });
+ }
+ };
+ const Step = struct { keys: []const u8, want: []const u8 };
+ for ([_]Step{
+ .{ .keys = " '", .want = "1/3 C" },
+ .{ .keys = "\x1b '", .want = "2/3 B" },
+ .{ .keys = "o", .want = "3/3 A" },
+ .{ .keys = "o", .want = "3/3 A" },
+ .{ .keys = "i", .want = "2/3 B" },
+ .{ .keys = "i", .want = "1/3 C" },
+ .{ .keys = "\x1bj '", .want = "1/3 C" },
+ .{ .keys = "\x1b '", .want = "2/3 B" },
+ }, 0..) |step, n| {
+ for (step.keys) |c| switch (c) {
+ 0x1b => p.update(.{ .key = .{ .cp = Key.escape } }),
+ // Ctrl-o and Ctrl-i alone in a step: in the picker.
+ 'o', 'i' => p.update(.{ .key = .{ .cp = c, .ctrl = true } }),
+ else => p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } }),
+ };
+ errdefer std.debug.print("step {d}\n", .{n});
+ try std.testing.expectEqualStrings(step.want, try Shown.of(p, frame.allocator()));
+ if (n == 3) try std.testing.expect(std.mem.indexOf(u8, p.messages.headline().?.words(), "no picker before it") != null);
+ }
+ // Its Enter lands as any list's: the walk over, it the newest.
+ p.update(.{ .key = .{ .cp = Key.enter } });
+ p.sync();
+ p.update(.{ .key = .{ .cp = ' ', .text = " " } });
+ p.update(.{ .key = .{ .cp = '\'', .text = "'" } });
+ try std.testing.expectEqualStrings("1/3 B", try Shown.of(p, frame.allocator()));
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ // A list word naming a picker no longer kept: said, and passed by.
+ const reader = p.view().active;
+ const t = &p.panes[reader].?.trail;
+ try std.testing.expect(t.n == 3 and t.cur == 2 and t.steps[1] == .list);
+ t.steps[1].list.index = 999_999;
+ p.update(.{ .key = .{ .cp = 'o', .ctrl = true } });
+ p.sync();
+ try std.testing.expect(std.mem.indexOf(u8, p.messages.headline().?.words(), "that list is gone: the last 8 are kept") != null);
+ try std.testing.expect(live(p) == null);
+ try std.testing.expectEqualStrings("base.zig", std.Io.Dir.path.basename(p.panes[p.view().active].?.file.?.path));
+ try std.testing.expectEqual(@as(u8, 0), p.panes[p.view().active].?.trail.cur);
+}
diff --git a/core/keys.zig b/core/keys.zig
index e9be2461..ea25c2f7 100644
--- a/core/keys.zig
+++ b/core/keys.zig
@@ -232,6 +232,7 @@ pub fn handleKey(p: *Pardes, key: Key) void {
// A tag in a typing state takes every key (TagState: Help, describe-key).
if (p.view().tag_state.kind != .rest) return tagStateKey(p, key);
Prompt.keyAtRest(p, key);
+ @import("Pick.zig").keyAtRest(p, key);
// Esc takes a hover's ghost lines away (SPEC §3.5) before anything else
// it does.
if (p.lsp_ask.hover != null and hit(key, config.escape)) {