summaryrefslogtreecommitdiff
path: root/core/mouse.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-26 09:40:17 -0300
committerGabriel Schneider <[email protected]>2026-11-26 10:28:44 -0300
commit8d90edcec1ba432d0f67ecc3a79eb6bf193369ff (patch)
tree2adbc108fb6d5076f9dba35afe850d14644ff801 /core/mouse.zig
parent8959b031dc330b4da21c0e89e0831d6fadbcd757 (diff)
downloadpardes-8d90edcec1ba432d0f67ecc3a79eb6bf193369ff.tar.gz
pardes-8d90edcec1ba432d0f67ecc3a79eb6bf193369ff.zip
TagState, tagline, Band, draw, layout, mouse, Pick, Trail, Core: out of rest a pane's tag stays exactly as at rest and what the keyboard drives hangs under it, the head on the row under the tag's rows, then the band (UX DESIGN M, binding; the user, looking at a picker started in an empty pane whose tag had become `^ ␣ f Find ascii 1/1`: "doesn't it make sense to the search just show below the tagline instead of being search tagline then results?", then "Keep consistent, idk, yes"): for every state the keyboard drives (rolled and unrolled levels, `"`, Help, describe-key, every picker, every text prompt, `:`, rename, code actions) the tag keeps its mark, owner, trail, path, Keep, computed words and own text, its rows and its wrapping, the box alone saying `^` while typing; THE WAY IT WAS: the head (TagState.head) was the tag's text after a cut-down prefix (D1's owner and newest step, tagline.pathPrefix's out-of-rest branch, Trail's `.newest` part), so the path, Keep and the user's text left the screen while you typed, the key cells sat on the tag's row for a level and jumped with it, and a picker's preview in a reading pane would have named the previewed file had the path stayed; THE CHANGE: TagState.head is the head alone, laid out from the tag's text column on rows of its own (Builder's `lead` gone), and TagState.asking the question a tag says, which stays in the tag (UX D13, M1: questions unchanged); tagline.shownTail is the question or the own text in every state, pathPrefix the path in every state (the out-of-rest branch and Trail's `.newest` part, `newest_cells` and the `cut` buffers deleted); a pane a picker previews in names its own file, the one Pick.showText set aside (tagline.named, tagWords, and Trail.reading asking the same file, so its tint, Keep and words are the rest ones); a pane made for the picker (it has no rest) shows its owner's word alone, `‹@pN ›` (M3; P1's reading 2 reversed); Band.covered is the tag's rows at rest, then the head's rows, then the band's, `over` = head + band (no rows the head reused: M4), layout.headRows the head's own rows and floorRows the tag's rows plus the head's and the band's (a head that does not fit borrows from its column as a band does); draw.zig joinBand paints the head's rows as the band layer's first rows (its spans' inks moved there from paintPaneTag, its caret the band layer's cursor), the band's under them, the spines from the head's key cells on its own row; render draws the host's tag with its rest rows; mouse: a press on a tag out of rest ends its state as Esc does and then does what it does at rest (M3; a pane made for a picker goes with it and the press with it), bandPoint reads the head's rows as the band layer's first, and B1 in the head's field puts the field's caret there; edit.zig refuses an edit of a tag only while it asks; RUN (TEST FIRST): five new tests, each failing on the base (M2, 8959b031dc33) and passing now: TagState "out of rest a tag is drawn as at rest, the head hanging under it ..." (a `.list` picker in a reading pane that walked near.txt -> far.txt: the tag's rows cell for cell as at rest but the box, its path far.txt while the body previews near.txt, the head `␣ l Refs ... 1/1` on the next row, its count the row's last cells, the band under it; Esc, the rows as before: failed on the base at the tag text, `near.txt:2 › ␣ l Refs ...`), TagState "the key cells are one thing growing on the row under the tag ..." (`␣`, `␣ f`, `␣ f Find` in the same cells of the row under a two-row tag: failed on the base, `␣` on the tag's row), TagState "a click that gives the keyboard to another pane ends a level ...; one in the level's own tag ends it too, then does what it does there at rest ..." (was "... one in the level's own tag keeps it"; B1 on the tag's own word ends SPC's level and gives the tag the keyboard, B2 on `Wrap` ends Help and toggles wrap: failed on the base, the level kept), Pick "a pane made for a picker has no rest: its tag is its owner's word alone, `‹@pN ›` ..." (B3 on it: the picker ends, the made pane goes, nothing under the press looked at: failed on the base, its tag `␣ f Find ...`), Command ": hangs its field under the tag, which stays as at rest; `:` on the empty field gives the keyboard to that tag's own text right above it ..." (failed on the base, the tag text `: ...`); the expectations that read the head through the tag's text read it from TagState.head now (TagState's testTag, Prompt's and Command's headOf, Pick's headOf; bindings, Messages, lsp/Ask, Trail, Band, draw, views: ~40), and the ones that read a body's first row while a prompt is up read the rows under the head's (Prompt's `/`, `s`, `|` tests, body_layer's current-place test, Ask's rename); views' short-column picker test runs at 15 rows (the head's row is one more covered row: at 12 the band had none left); the process test msg waits for the second reload by the notice row's `×2` (the pane's one line is under the `s` prompt's head now); AND A FAULT THIS MADE VISIBLE: code actions drew their edit's ghost lines from the body's top under a band drawn over it (Pick.previewing was a place's preview alone), so an edit on the first rows of a file was under the band; with the head's row one more covered row, test/behaviour/language_servers.zig's "SPC l a lists the server's code actions ..." failed (`let x = sum(1, 2);` at line 4 under the head and a 4-row band, not on the screen); THE FIX: code actions' body is their preview from the first (UX DESIGN I1: "a picker and code actions (whose body is the preview) keep D6"): Pick.previewing is true for them, so the body starts under the head and the band as a picker's preview does; the behaviour test passes now; GATES (Debug tui, this change): core-test 1166/1340 (174 skipped; M2's gate 1155/1329), shell-test 1381/1384 (3 skipped), behaviour-test 287/287 and --replay 287/287, pane-test 184/185 (1 skipped), term-test 17/17, kitty-test 45/45 (these three before the code-actions fix and two renames), process-test 8 of 149 failed (3 skipped): exactly the goldens with a frame out of rest (find, fsearch, leader, lsp, msg, pipe, selregex, ttyhelp), re-recorded and explained by the next change; the dump does not change (no pane or view field); no frame or perf gate (the user's rule of 2026-11-26); load 4.2 to 14.3
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE
Diffstat (limited to 'core/mouse.zig')
-rw-r--r--core/mouse.zig70
1 files changed, 51 insertions, 19 deletions
diff --git a/core/mouse.zig b/core/mouse.zig
index 04bbaeb4..2e55ba95 100644
--- a/core/mouse.zig
+++ b/core/mouse.zig
@@ -726,6 +726,15 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void {
if (m.kind == .press) {
tagline.exitHeader(p);
}
+ // A press on a tag out of rest ends its state as Esc does, the bodies
+ // back, then does what a press there does at rest: the tag is drawn as
+ // at rest, and its words act as they do then (UX DESIGN M3). A pane made
+ // for a picker goes with it, and the press with it: it was the Esc.
+ if (m.kind == .press) if (hostTagAt(p, mcol, mrow)) |id| {
+ const serial = p.panes[id].?.serial;
+ pardes.TagState.toRest(p);
+ if (p.paneBySerial(serial) == null) return;
+ };
if (m.kind == .press) if (bandPoint(p, mcol, mrow)) |point| return bandPress(p, m.button, point);
switch (m.button) {
@@ -920,30 +929,43 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void {
}
}
-/// A band's row, or a head's row past its tag's own (`head`), drawn over
-/// the body: a covered row belongs to the band, never to the body under it
-/// (UX DESIGN I1).
+/// The pane out of rest whose tag (its rows at rest, Band.covered) a press
+/// is on: a window's layer hit, or a grid cell.
+fn hostTagAt(p: *Pardes, mcol: u16, mrow: u16) ?usize {
+ const v = p.view();
+ const id = pardes.TagState.hostOf(p) orelse return null;
+ if (v.pointer_tag_hit) |hit| return if (hit.kind == .pane and hit.id == id) id else null;
+ if (paneAt(p, mcol, mrow) != id) return null;
+ const pane = p.panes[id].?;
+ const top = p.tagTop(pane, v.rects[id]);
+ return if (mrow >= top and mrow < top + pardes.Band.covered(p, pane, id).tag) id else null;
+}
+
+/// A head's row (`head`) or a band's under it, drawn over the body: a
+/// covered row belongs to them, never to the body under it (UX DESIGN I1,
+/// M2).
const BandPoint = struct { id: usize, line: u16, col: u16, head: bool = false };
-/// The band row and column (at the tagline's pitch) a press is on, or the
-/// head's row over the body: a window's layer hit, or a grid cell under a
-/// tag's own rows.
+/// The head's or the band's row and column (at the tagline's pitch) a
+/// press is on: a window's layer hit, or a grid cell under a tag.
fn bandPoint(p: *Pardes, mcol: u16, mrow: u16) ?BandPoint {
const v = p.view();
if (v.pointer_tag_hit) |hit| {
- if (hit.kind == .band) return .{ .id = hit.id, .line = hit.line, .col = hit.col };
- const pane = (if (hit.kind == .pane and hit.id < p.panes.len) p.panes[hit.id] else null) orelse return null;
- return if (hit.line >= pane.tag_rows) .{ .id = hit.id, .line = hit.line, .col = hit.col, .head = true } else null;
+ if (hit.kind != .band) return null;
+ const pane = (if (hit.id < p.panes.len) p.panes[hit.id] else null) orelse return null;
+ const head = pardes.Band.covered(p, pane, hit.id).head;
+ if (hit.line < head) return .{ .id = hit.id, .line = hit.line, .col = hit.col, .head = true };
+ return .{ .id = hit.id, .line = hit.line - head, .col = hit.col };
}
const id = paneAt(p, mcol, mrow) orelse return null;
const pane = p.panes[id].?;
const at = pardes.Band.covered(p, pane, id);
const r = v.rects[id];
- const top = p.tagTop(pane, r);
- if (mrow < top + @min(pane.tag_rows, at.text) or mrow >= top + at.text + at.band or mcol < r.x + TAG_TEXT_INSET) return null;
+ const top = p.tagTop(pane, r) + at.tag;
+ if (mrow < top or mrow >= top + at.over or mcol < r.x + TAG_TEXT_INSET) return null;
const col = mcol - (r.x + TAG_TEXT_INSET);
- if (mrow < top + at.text) return .{ .id = id, .line = mrow - top, .col = col, .head = true };
- return .{ .id = id, .line = mrow - top - at.text, .col = col };
+ if (mrow < top + at.head) return .{ .id = id, .line = mrow - top, .col = col, .head = true };
+ return .{ .id = id, .line = mrow - top - at.head, .col = col };
}
/// A press on a band (Band.zig), read-only text: the select button puts
@@ -952,14 +974,24 @@ fn bandPoint(p: *Pardes, mcol: u16, mrow: u16) ?BandPoint {
fn bandPress(p: *Pardes, button: Mouse.Button, point: BandPoint) void {
const v = p.view();
const arena = p.scratch.allocator();
- // A head's row over the body: its words as the tag's first row's.
+ // The head's rows: the select button in its field puts the field's
+ // caret there (UX DESIGN M6); its words run and are looked at as a
+ // tag's.
if (point.head) {
+ const h = (pardes.TagState.head(p, arena, p.panes[point.id].?) catch return) orelse return;
+ const shown = tagline.wrapTag(p.settings.tab, arena, h.text, tagline.tagWidth(p, point.id)) catch return;
+ const text = modal.lineSlice(shown.text, point.line);
+ const raw = panes.File.rawAtDisplay(p.settings.tab, text, point.col);
+ if (button == config.select_button) {
+ const caret = h.caret orelse return;
+ const field = &v.tag_state.field;
+ const at = shown.toReal(modal.lineStartOffset(shown.text, point.line) + modal.graphemeStart(text, raw));
+ const start = caret - field.caret;
+ if (at >= start and at <= start + field.len) field.caret = @intCast(at - start);
+ return;
+ }
if (button != config.exec_button and button != config.look_button) return;
- const shown = (tagline.shownTag(p, arena, p.panes[point.id].?) catch return).text;
- var lines = std.mem.splitScalar(u8, shown, '\n');
- for (0..point.line) |_| _ = lines.next();
- const text = lines.next() orelse return;
- const b = tagline.wordBoundsAtCol(text, panes.File.rawAtDisplay(p.settings.tab, text, point.col)) orelse return;
+ const b = tagline.wordBoundsAtCol(text, raw) orelse return;
if (b.lo == b.hi) return;
const word = text[b.lo..b.hi];
if (v.tag_state.kind == .pick and button == config.exec_button) return exec.runBuiltin(p, config.exec_cmd, v.active, "", word);