summaryrefslogtreecommitdiff
path: root/core/body_layer.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-25 10:02:29 -0300
committerGabriel Schneider <[email protected]>2026-11-25 10:02:29 -0300
commit98f5abfc10d9984a69940a6805d974018e5ea01e (patch)
tree6742290772cb87a8cfdd57bd3fa85d5b4043f21f /core/body_layer.zig
parenta6d2b61bd78768cf4bbf177717ffea319825de69 (diff)
downloadpardes-98f5abfc10d9984a69940a6805d974018e5ea01e.tar.gz
pardes-98f5abfc10d9984a69940a6805d974018e5ea01e.zip
Messages, body_layer, normal, mouse, Core: a message's detail unrolls only on request (UX D13, E5 fix 3): K with one selection on a line a message with a detail names, SPC e there, or a Look (B3) on its words after the line unrolls it under that line, and the caret leaving the line (or the keyboard another pane) rolls it up; the caret passing a line never inserts or removes rows; THE CAUSE: Messages.detailUnder showed the detail of the message naming the caret's line whenever the caret was on it (C's rule, spec §10.2), so j over a build error pushed the text below down and k pulled it back (UX A16, E2 "detail still unrolls under the caret"); THE FIX: Said.open (the question's Diff's flag, already in the dump and the digest; its doc said "whatever the caret" and nothing read it) is the request: detailUnder shows the message whose words the caret's line shows (the first naming it, firstAt, as messageGhosts draws them) only while it is open, and a question's Diff under its place whatever the caret; Messages.detailAt finds it (not a question's: its Diff is `d`); normal.zig's K takes it with one selection, else keep's prompt as before; Messages.act (SPC e) unrolls it first when the caret's line has one not shown, the walk as before when asked again; mouse.zig: a Look on its words after the line (body_layer.messageAt: from their glyph two blanks after the line, read from the frame drawn last, as wordAt reads a detail's word; wordAt and it share drawnRow) toggles it; Core.update: around a key and a click, Messages.unrolledAt/rollUp roll every unrolled detail (not a question's Diff) up when the keyboard's pane or its caret's line changed (a motion along the line, or a click on the detail, which puts the caret on the line it explains, keeps it: C's G-fixed rule holds, the detail's rows are read-only text for the mouse); nothing read with no detail unrolled; the Message builtin's doc says it (docs/typ/builtins-tui.json and -gui.json the same text); TEST FIRST: body_layer.zig "a message's detail unrolls only on request (UX D13): the caret passing its line inserts no rows; K there unrolls it ...; K with two selections is keep's" (fails on the base at body_layer.zig:1346: the caret on line 3 put its detail under it); C's two tests ask for the detail (err.open, and K after k k) where they set the caret; core-test 1084/1255 (171 skipped), process-test 0 of 147 failed (no golden moved); a user hit it: every build error and diagnostic with detail lines pushed the text below down as the caret passed
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE
Diffstat (limited to 'core/body_layer.zig')
-rw-r--r--core/body_layer.zig113
1 files changed, 105 insertions, 8 deletions
diff --git a/core/body_layer.zig b/core/body_layer.zig
index 0107b3e0..f00da4a9 100644
--- a/core/body_layer.zig
+++ b/core/body_layer.zig
@@ -641,6 +641,28 @@ fn messageGhosts(p: *Pardes, s: *Surface, pane: *Pane, tx: u16, tw: u16, body_y:
/// frame drawn last (its body layer when it has one, else the grid): a
/// message's detail is text no buffer holds, read as it is shown.
pub fn wordAt(p: *Pardes, arena: std.mem.Allocator, id: usize, row: usize, col: usize) !?[]const u8 {
+ const text = try drawnRow(p, arena, id, row) orelse return null;
+ const b = pardes.tagline.wordBoundsAtCol(text, panes.File.rawAtDisplay(p.settings.tab, text, col)) orelse return null;
+ if (b.lo == b.hi) return null;
+ return text[b.lo..b.hi];
+}
+
+/// The message whose words are drawn after its line at body row `row`,
+/// text column `col` of pane `id` in the frame drawn last, when it has a
+/// detail: a Look there unrolls it (UX D13). The words start at their
+/// glyph, two blanks after the line (messageGhosts).
+pub fn messageAt(p: *Pardes, arena: std.mem.Allocator, id: usize, row: u16, col: usize) !?*pardes.Messages.Said {
+ const pane = p.panes[id] orelse return null;
+ const said = pardes.Messages.detailAt(p, pane, pane.wrapAt(p.settings.tab, pane.textRow(row)).line) orelse return null;
+ const text = try drawnRow(p, arena, id, row) orelse return null;
+ var mark: [8]u8 = undefined;
+ const at = std.mem.lastIndexOf(u8, text, std.fmt.bufPrint(&mark, " {s} ", .{said.kind.glyph()}) catch return null) orelse return null;
+ return if (panes.File.rawAtDisplay(p.settings.tab, text, col) >= at + 2) said else null;
+}
+
+/// Body row `row` of pane `id` as the frame drawn last shows it: its body
+/// layer's when it has one, else the grid's.
+fn drawnRow(p: *Pardes, arena: std.mem.Allocator, id: usize, row: usize) !?[]const u8 {
const layer = &p.surface.body_layers[id];
const body = (p.surface.region(.body, id) orelse return null).rect;
var text: std.ArrayList(u8) = .empty;
@@ -651,9 +673,7 @@ pub fn wordAt(p: *Pardes, arena: std.mem.Allocator, id: usize, row: usize, col:
if (row >= body.h) return null;
for (0..body.w) |x| try text.appendSlice(arena, p.surface.at(body.x + @as(u16, @intCast(x)), body.y + @as(u16, @intCast(row))).grapheme());
}
- const b = pardes.tagline.wordBoundsAtCol(text.items, panes.File.rawAtDisplay(p.settings.tab, text.items, col)) orelse return null;
- if (b.lo == b.hi) return null;
- return text.items[b.lo..b.hi];
+ return text.items;
}
/// A picker's landing line (UX D7): its text on the hit ground across
@@ -1141,7 +1161,7 @@ fn rowText(s: *const Surface, x: u16, y: u16, buf: []u8) []const u8 {
return buf[0..n];
}
-test "a build error is said where its cause is: the mark on its file's tag, its words after its line, its detail under the caret's line pushing the rows below down, the walk on the notice row" {
+test "a build error is said where its cause is: the mark on its file's tag, its words after its line, its detail, asked for, under its line pushing the rows below down, the walk on the notice row" {
const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 20 });
defer p.deinit();
const pane = try p.setTestFile("one\ntwo\nthree\nfour\nfive\nsix\n");
@@ -1172,8 +1192,10 @@ test "a build error is said where its cause is: the mark on its file's tag, its
// elsewhere.
try std.testing.expect(std.mem.indexOf(u8, rowText(s, body.x, body.y + 2, &buf), "three \u{2717} expected 2 argument(s), found 3") != null);
try std.testing.expect(std.mem.indexOf(u8, rowText(s, body.x, body.y + 3, &buf), "four") != null);
- // The caret on line 3: its detail under it, the rows below two rows down.
+ // The caret on line 3 and its detail asked for (K, UX D13): under the
+ // line, the rows below two rows down.
pane.body.cur_row = 2;
+ err.open = true;
_ = frame.reset(.retain_capacity);
s = try p.render(frame.allocator());
try std.testing.expect(std.mem.indexOf(u8, rowText(s, body.x, body.y + 3, &buf), "const x = f(1, 2, 3);") != null);
@@ -1202,6 +1224,7 @@ test "a click under a message's detail lands on the row drawn there, a click on
err.detail_len = 2;
pane.focus = .body;
pane.body.cur_row = 2;
+ err.open = true;
p.sync();
var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
defer frame.deinit();
@@ -1215,9 +1238,14 @@ test "a click under a message's detail lands on the row drawn there, a click on
p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = x, .row = body.y + 6 } });
p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = x, .row = body.y + 6 } });
try std.testing.expectEqual(@as(i32, 4), pane.body.cur_row);
- // On line 3 again, its detail drawn: a click on the detail is on the
- // line it explains, and the detail stays.
- pane.body.cur_row = 2;
+ // On line 3 again, its detail asked for again (the click, a motion,
+ // rolled it up): a click on the detail is on the line it explains, and
+ // the detail stays.
+ try std.testing.expect(!err.open);
+ p.update(.{ .key = .{ .cp = 'k' } });
+ p.update(.{ .key = .{ .cp = 'k' } });
+ p.update(.{ .key = .{ .cp = 'K' } });
+ try std.testing.expect(err.open);
_ = frame.reset(.retain_capacity);
s = try p.render(frame.allocator());
const wrap_at = std.mem.indexOf(u8, rowText(s, body.x, body.y + 3, &buf), "Wrap").?;
@@ -1317,3 +1345,72 @@ test "a motion root's level paints its targets in place of their lines' numbers,
s = try p.render(a);
try std.testing.expectEqualStrings("5", Field.of(s, gutter, body.y + 4, number, &buf));
}
+
+test "a message's detail unrolls only on request (UX D13): the caret passing its line inserts no rows; K there unrolls it under the line and the caret leaving the line rolls it up; SPC e there unrolls it; a Look on its words after the line unrolls it; K with two selections is keep's" {
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 20 });
+ defer p.deinit();
+ const pane = try p.setTestFile("one\ntwo\nthree\nfour\nfive\nsix\n");
+ const id = p.view().active;
+ const err = pardes.Messages.keep(p, .@"error", 0, "@p9 zig build", "exit 1");
+ err.places[0] = .{ .line = 3, .col = 1 };
+ err.places[0].path.set("/test.txt");
+ err.places[0].text.set("expected 2 argument(s), found 3");
+ err.places_len = 1;
+ err.detail[0] = .{};
+ err.detail[0].set("const x = f(1, 2, 3);");
+ err.detail_len = 1;
+ pane.focus = .body;
+ p.sync();
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ var buf: [512]u8 = undefined;
+ // The caret onto line 3 and past it: no row inserted or removed.
+ p.update(.{ .key = .{ .cp = 'j' } });
+ p.update(.{ .key = .{ .cp = 'j' } });
+ try std.testing.expectEqual(@as(i32, 2), pane.body.cur_row);
+ var s = try p.render(frame.allocator());
+ const body = s.region(.body, id).?.rect;
+ try std.testing.expect(std.mem.indexOf(u8, rowText(s, body.x, body.y + 2, &buf), "three \u{2717} expected") != null);
+ try std.testing.expect(std.mem.indexOf(u8, rowText(s, body.x, body.y + 3, &buf), "four") != null);
+ // K there: its detail under the line, the rows below one lower; no
+ // keep prompt.
+ p.update(.{ .key = .{ .cp = 'K' } });
+ try std.testing.expectEqual(pardes.TagState.Kind.rest, p.view().tag_state.kind);
+ _ = frame.reset(.retain_capacity);
+ s = try p.render(frame.allocator());
+ try std.testing.expect(std.mem.indexOf(u8, rowText(s, body.x, body.y + 3, &buf), "const x = f(1, 2, 3);") != null);
+ try std.testing.expect(std.mem.indexOf(u8, rowText(s, body.x, body.y + 4, &buf), "four") != null);
+ // The next motion rolls it up; back on the line, nothing comes back.
+ p.update(.{ .key = .{ .cp = 'j' } });
+ p.update(.{ .key = .{ .cp = 'k' } });
+ try std.testing.expect(!err.open);
+ _ = frame.reset(.retain_capacity);
+ s = try p.render(frame.allocator());
+ try std.testing.expect(std.mem.indexOf(u8, rowText(s, body.x, body.y + 3, &buf), "four") != null);
+ // SPC e there: unrolled, the error still live; K rolls it up.
+ p.update(.{ .key = .{ .cp = ' ' } });
+ p.update(.{ .key = .{ .cp = 'e' } });
+ try std.testing.expect(err.open);
+ try std.testing.expectEqual(@as(usize, 1), p.messages.live_len);
+ _ = frame.reset(.retain_capacity);
+ s = try p.render(frame.allocator());
+ try std.testing.expect(std.mem.indexOf(u8, rowText(s, body.x, body.y + 3, &buf), "const x = f(1, 2, 3);") != null);
+ p.update(.{ .key = .{ .cp = 'K' } });
+ try std.testing.expect(!err.open);
+ // A Look (B3) on its words after the line: unrolled, the caret where
+ // it was.
+ _ = frame.reset(.retain_capacity);
+ s = try p.render(frame.allocator());
+ const words = std.mem.indexOf(u8, rowText(s, body.x, body.y + 2, &buf), "expected").?;
+ const wx = body.x + @as(u16, @intCast(words)) + 1;
+ p.update(.{ .mouse = .{ .button = .right, .kind = .press, .col = wx, .row = body.y + 2 } });
+ p.update(.{ .mouse = .{ .button = .right, .kind = .release, .col = wx, .row = body.y + 2 } });
+ while (p.nextEffect()) |_| {}
+ try std.testing.expect(err.open);
+ try std.testing.expectEqual(@as(i32, 2), pane.body.cur_row);
+ // K with two selections is keep's prompt, the detail as it was.
+ p.update(.{ .key = .{ .cp = 'C' } });
+ try std.testing.expect(pane.body.nsel > 0);
+ p.update(.{ .key = .{ .cp = 'K' } });
+ try std.testing.expectEqual(pardes.TagState.Kind.prompt, p.view().tag_state.kind);
+}