summaryrefslogtreecommitdiff
path: root/core/Pick.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-25 21:40:17 -0300
committerGabriel Schneider <[email protected]>2026-11-25 23:31:32 -0300
commit0e9d91dcf8bf42ee6c9b3a777d6cac658b83f97a (patch)
tree6d82ca5200d997129aaa898314d5e89bb2bc87e0 /core/Pick.zig
parent1e8787e0b2eb3eaa4991a5160f6e5c35ba6f132e (diff)
downloadpardes-0e9d91dcf8bf42ee6c9b3a777d6cac658b83f97a.tar.gz
pardes-0e9d91dcf8bf42ee6c9b3a777d6cac658b83f97a.zip
layout, Trail, Pick, look: a new pane goes into free space before it splits a pane: an untouched `+New` is taken, an empty column filled (UX DESIGN J, binding; the user: "the New panes that are empty should be taken over by the previews since doesn't make sense to keep them, this should also apply to empty colums"; p1-02: SPC f f from an empty +New made its landing pane under it and squeezed main.zig from 8 body rows to 3, p1-03: after Enter the +New kept 6 empty rows and the file got 4; at 150x45 a Look from a held main.zig split it and left an empty column empty); THE RULE: free space is an untouched pane (Trail.untouched: a +New never typed into, no undo history, its body empty, still so named, not kept, not folded, and no 9P open holding it: a look or exec open answered with it, exec.leased, or an open of one of its own files, so a script's pane/new and its `look` stay its own) or an empty column; every opening that makes a pane but New and 9P's pane/new looks for it first (layout.placeNew → freeSpace): the asking pane when it is untouched, else the nearest, in its column below it then above, then the columns to its right, nearest first, then to its left; asked from a column's tag, that column alone; an untouched pane is taken (takePane: its place, rows and weight, layout.replacePane; it closes at the step's end, Pardes.unplaced) where its rows hold the new pane's tag and two rows, as every placement leaves; a file taken into it keeps its number (@pN and its 9P state, as Trail.show's step does, the file a revision on), a terminal, kind, listing, output or Zerox twin its own (a shell's spawn and a kind's jobs went to the host by their serial as they were made; a twin's revision is its text's); a jump from an untouched pane opens its reader in its place with no owner word, its trail starting at the file (Trail.reader with no owner); a picker from one previews in it (Pick.hostIn: no pane made), Esc gives it back empty, Enter lands in it, a reading pane whose trail starts with the list word, and S-Enter and C-v there are Enter; a picker from a held pane with no reader previews in the nearest untouched pane, given back on Esc, and Enter makes it the held pane's reader by that number, or makes its landing pane in an empty column; C-v makes a column only with no free space; `Jumps new-pane`, S-Enter, C-s, a command's output, Term, +Help, +Search, a directory, the pager's +Diff go the same way; look.runSearch's 16 MB of room is the gpa's, freed, not the step's arena (core/fuzz.zig's 9P seed 610 under the new placement looked a word twice in one burst of requests, which come between steps, and asked that arena for a 75 MB node); RUN (TEST FIRST): layout.zig "free space first (UX J1)": a held pane's reader takes the +New below, above, right and left of it in that order, each by its number and in its rows, then splits as before, then takes an empty column whole; a jump from a +New, and one under Jumps new-pane, opens in it by its number; a +New typed into and emptied, kept, leased or with a file open over 9P is no free space; a command's output and a Term take a +New (shell-test); Pick.zig: a picker in a +New previews there, Esc, Enter and S-Enter; one from a held pane previews in a +New, Enter makes it the reader, C-v lands in an empty column with no column made; all four fail on the base's placement (the +New left, the landing made) and pass now; ninep/tree.zig's random placements kept every pane its tag and two rows only once a +New too short for the new pane's tag was passed by; ninep/cols.zig's column-tag command and behaviour/placement's look from a pane/new pane kept by the column-tag and 9P-open rules; two older Pick tests count panes after the step's end (the +New the Look took closes then); six tty goldens re-recorded, each the boot layout's +New taken by the pane made (nested's reader of the shell, diffstack's and pagercolor's +Diff, ttyhelp's +Help, look-fd-deep's reader, psearch's +Search, each now in the +New's rows under a shell that keeps all of its own); docs/typ/reference.typ's Placement says it; a user hit the old placement on every opening from or beside an empty +New or column; with the next change on it: core-test 1117/1290 (173 skipped; this change +4 and +1 skipped, the next +1), shell-test 1338/1341 (3 skipped; +5 and +1), pane-test 183/184, behaviour-test 280/280 and --replay 280/280 (the monkey's 20 seeds, 0 failures), process-test 0 of 147 failed (3 skipped, the six goldens moved), term-test 17/17, kitty-test 45/45, load 2.4 to 5.6; the frame and perf gate against a baseline recorded from the installed tree 1e8787e0b2eb (gpu/w2base, then gpu/walkui-W2): 76 of 77 frames byte-identical, frame 63 (a translucent addon picture over its pane) moved by this change: the veil pane takes the empty middle column whole instead of going under the third column's +New, which was typed into; the gui unit-test 1941/1945 (base 1935, no failure the base has not); perfops 121 of 121 within 0.1% (largest open on small per-op +0.0154%); perfab not measured (its pictures differ at frame 63); timedemos INFO text +2.26%, snake -1.46%, pdf +0.23% (spreads 2-3%); no dump layout change, so no fuzz or soak; load 2.9 to 4.8
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE
Diffstat (limited to 'core/Pick.zig')
-rw-r--r--core/Pick.zig145
1 files changed, 130 insertions, 15 deletions
diff --git a/core/Pick.zig b/core/Pick.zig
index b76020ca..2bcaf76f 100644
--- a/core/Pick.zig
+++ b/core/Pick.zig
@@ -233,9 +233,11 @@ fn make(p: *Pardes, source: Source) !*Pick {
}
/// 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 a pane made under
-/// it as its reader would be, empty until the preview fills it. The
-/// keyboard stays where it was: the landing pane is the tag's host.
+/// 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
+/// and is given back as it was on Esc; else a pane made where its reader
+/// would go, empty until the preview fills it. The keyboard stays where it
+/// was: the landing pane is the tag's host.
fn hostIn(p: *Pardes, pk: *Pick, from: usize) !void {
const asker = p.panes[from].?;
pk.owner = asker.serial;
@@ -247,13 +249,17 @@ fn hostIn(p: *Pardes, pk: *Pick, from: usize) !void {
p.view().active = from;
return;
}
- const reader = if (Trail.reading(p, asker)) from else Trail.readerOf(p, asker);
+ var reader = if (Trail.reading(p, asker)) from else Trail.readerOf(p, asker);
+ if (reader == null) if (layout.freeSpace(p, from, .reader)) |free| if (free == .pane) {
+ reader = free.pane;
+ };
pk.landing = p.panes[reader orelse try landingFor(p, from)].?.serial;
pk.made = reader == null;
p.view().active = from;
}
-/// A pane made under pane `from` for a picker, where its reader goes.
+/// A pane made for a picker where pane `from`'s reader goes: under it, or
+/// an empty column (layout.freeSpace).
fn landingFor(p: *Pardes, from: usize) !usize {
const asker = p.panes[from].?;
const free = p.freeSlot() orelse return error.NoPaneSlots;
@@ -1340,8 +1346,10 @@ const How = enum { walk, below, column, queue };
/// Enter: the current row, or the marked ones, looked at from the asking
/// pane (look.open, the walk's way: a reading pane steps, a held one's
/// reader does), the first as `how` says, the others each in a pane below.
-/// The list rolls into the landing pane's trail as its word (item 4).
-fn land(p: *Pardes, how: How) void {
+/// The list rolls into the landing pane's trail as its word (item 4). From
+/// an untouched pane S-Enter and C-v are Enter: it is the free space a new
+/// pane would take (UX J1).
+fn land(p: *Pardes, wanted: How) void {
const pk = live(p) orelse return;
var arena = std.heap.ArenaAllocator.init(p.gpa);
defer arena.deinit();
@@ -1352,7 +1360,7 @@ fn land(p: *Pardes, how: How) void {
pk.queue.clearRetainingCapacity();
pk.queue_bytes.clearRetainingCapacity();
pk.queue_at = 0;
- if (how == .queue) for (picked[1..]) |t| switch (t) {
+ if (wanted == .queue) for (picked[1..]) |t| switch (t) {
.place => |at| {
const q: Queued = .{ .path = @intCast(pk.queue_bytes.items.len), .len = @intCast(@min(at.path.len, std.math.maxInt(u16))), .line = std.math.lossyCast(u32, at.at.line), .col = std.math.lossyCast(u32, at.at.col) };
pk.queue_bytes.appendSlice(p.gpa, at.path[0..q.len]) catch break;
@@ -1360,13 +1368,16 @@ fn land(p: *Pardes, how: How) void {
},
else => {},
};
- // A step from the pane it lands in when that reads (its owner's reader
- // or itself), else from its owner, whose reader the place opens as.
- const landing = if (pk.made) null else p.paneBySerial(pk.landing);
TagState.toRest(p);
const v = p.view();
const owner = p.paneBySerial(pk.owner) orelse v.active;
- const from = if (how == .walk or how == .queue) landing orelse owner else owner;
+ const how: How = if ((wanted == .below or wanted == .column) and Trail.untouched(p, p.panes[owner].?)) .walk else wanted;
+ // A step from the pane it lands in when that reads (its owner's reader
+ // or itself), else from its owner, whose reader the place opens as:
+ // where the pane made for the picker was, or in the untouched pane it
+ // previewed in (UX J1), given back now.
+ const landing = p.paneBySerial(pk.landing) orelse owner;
+ const from = if ((how == .walk or how == .queue) and Trail.reading(p, p.panes[landing].?)) landing else owner;
v.active = from;
v.jumps.force = true;
for (picked, 0..) |t, k| switch (t) {
@@ -1383,9 +1394,11 @@ fn land(p: *Pardes, how: How) void {
else => listed(p, pk),
}
} else if (k == 0 and how == .column) {
- layout.newColumn(p, from);
- const c = layout.activeColumn(p) orelse continue;
- p.exec_column = c;
+ // A column made only where there is no free space (UX J1).
+ if (layout.freeSpace(p, from, .doc) == null) {
+ layout.newColumn(p, from);
+ p.exec_column = layout.activeColumn(p) orelse continue;
+ }
defer p.exec_column = null;
pardes.tagline.exitHeader(p);
_ = look.open(p, from, at.path, at.at, .below);
@@ -1978,6 +1991,7 @@ test "Enter lands as a walk step in the reading pane; S-Enter opens below; from
const b_path = try testFile(p, &tmp, "beta.zig", "one\ntwo\nthree\n");
defer p.gpa.free(b_path);
look.lookAt(p, p.view().active, a_path);
+ p.sync();
const id = p.view().active;
const npanes = paneCount(p);
open(p, id, .list, "Refs", "", "beta.zig:3:1 three\n");
@@ -2193,6 +2207,7 @@ test "a picker from a reading pane unrolls in that pane, its own text set aside
const b_path = try testFile(p, &tmp, "beta.zig", "one\ntwo\nthree\n");
defer p.gpa.free(b_path);
look.lookAt(p, p.view().active, a_path);
+ p.sync();
const id = p.view().active;
try std.testing.expect(Trail.reading(p, p.panes[id].?));
const npanes = paneCount(p);
@@ -2620,3 +2635,103 @@ test "Backspace on a Messages picker's empty field goes back to the level it was
p.sync();
_ = try p.render(frame.allocator());
}
+
+test "a picker started in an untouched +New previews in it (UX J1): no pane made, Esc gives it back empty, Enter lands in it, the same pane by its number, reading, its trail starting at the list word; S-Enter there is Enter" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 });
+ defer p.deinit();
+ p.settings.jumps = .walk;
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ const b_path = try testFile(p, &tmp, "beta.zig", "one\ntwo\nthree\n");
+ defer p.gpa.free(b_path);
+ const rows = try std.fmt.allocPrint(p.gpa, "{s}:3:1 three\n", .{b_path});
+ defer p.gpa.free(rows);
+ _ = try p.setTestFile("first\n");
+ for ([_]bool{ false, true }) |shift| {
+ exec.runBuiltin(p, .New, 0, "New", null);
+ p.sync();
+ const scratch = p.view().active;
+ const serial = p.panes[scratch].?.serial;
+ const top = p.view().rects[scratch].y;
+ const npanes = paneCount(p);
+ try std.testing.expect(Trail.untouched(p, p.panes[scratch].?));
+ open(p, scratch, .list, "Refs", "", rows);
+ settle(p);
+ p.update(.tick);
+ try std.testing.expect(!live(p).?.made);
+ try std.testing.expectEqual(serial, live(p).?.landing);
+ try std.testing.expectEqual(npanes, paneCount(p));
+ try std.testing.expectEqualStrings(b_path, p.panes[scratch].?.file.?.path);
+ // Esc: the +New as it was, still free space.
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ try std.testing.expectEqual(npanes, paneCount(p));
+ try std.testing.expect(Trail.untouched(p, p.panes[scratch].?));
+ try std.testing.expectEqual(serial, p.panes[scratch].?.serial);
+ // Enter (or S-Enter): the file in it.
+ open(p, scratch, .list, "Refs", "", rows);
+ settle(p);
+ p.update(.{ .key = .{ .cp = Key.enter, .shift = shift } });
+ p.sync();
+ try std.testing.expect(live(p) == null);
+ const here = p.panes[p.view().active].?;
+ try std.testing.expectEqual(serial, here.serial);
+ try std.testing.expectEqualStrings(b_path, here.file.?.path);
+ try std.testing.expectEqual(@as(i32, 2), here.body.cur_row);
+ try std.testing.expectEqual(npanes, paneCount(p));
+ try std.testing.expectEqual(top, p.view().rects[p.view().active].y);
+ try std.testing.expect(Trail.reading(p, here));
+ try std.testing.expectEqual(@as(u8, 2), here.trail.n);
+ try std.testing.expect(here.trail.steps[0] == .list and here.trail.steps[1] == .place);
+ }
+}
+
+test "a picker from a held pane previews in an untouched +New (UX J1): Esc gives it back empty, Enter makes it the held pane's reader by its number; C-v lands in an empty column rather than making one" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 });
+ defer p.deinit();
+ p.settings.jumps = .walk;
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ const b_path = try testFile(p, &tmp, "beta.zig", "one\ntwo\nthree\n");
+ defer p.gpa.free(b_path);
+ const rows = try std.fmt.allocPrint(p.gpa, "{s}:3:1 three\n", .{b_path});
+ defer p.gpa.free(rows);
+ _ = try p.setTestFile("held\n");
+ const held = p.view().active;
+ Trail.keep(p.panes[held].?);
+ exec.runBuiltin(p, .New, held, "New", null);
+ p.sync();
+ const scratch = p.view().active;
+ const serial = p.panes[scratch].?.serial;
+ p.view().active = held;
+ const npanes = paneCount(p);
+ open(p, held, .list, "Refs", "", rows);
+ settle(p);
+ p.update(.tick);
+ try std.testing.expect(!live(p).?.made);
+ try std.testing.expectEqual(serial, live(p).?.landing);
+ try std.testing.expectEqualStrings(b_path, p.panes[scratch].?.file.?.path);
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ try std.testing.expectEqual(npanes, paneCount(p));
+ try std.testing.expect(Trail.untouched(p, p.panes[scratch].?));
+ open(p, held, .list, "Refs", "", rows);
+ settle(p);
+ p.update(.{ .key = .{ .cp = Key.enter } });
+ p.sync();
+ const reader = Trail.readerOf(p, p.panes[held].?).?;
+ try std.testing.expectEqual(serial, p.panes[reader].?.serial);
+ try std.testing.expectEqualStrings(b_path, p.panes[reader].?.file.?.path);
+ try std.testing.expectEqual(p.panes[held].?.serial, p.panes[reader].?.trail.steps[0].owner);
+ try std.testing.expectEqual(npanes, paneCount(p));
+ // C-v with an empty column there: the place goes in it.
+ Trail.keep(p.panes[reader].?);
+ const c = layout.insertColumn(p, layout.findPane(p, held).?.col, false).?;
+ p.sync();
+ const ncol = p.view().ncol;
+ open(p, held, .list, "Refs", "", rows);
+ settle(p);
+ p.update(.{ .key = .{ .cp = 'v', .ctrl = true } });
+ p.sync();
+ try std.testing.expectEqual(ncol, p.view().ncol);
+ try std.testing.expectEqual(c, layout.findPane(p, p.view().active).?.col);
+ try std.testing.expectEqualStrings(b_path, p.panes[p.view().active].?.file.?.path);
+}