diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-26 12:44:35 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-26 13:02:49 -0300 |
| commit | 51f211d694beff9a389ab519f2286cef077adb81 (patch) | |
| tree | 2df93ee551f2820011f6f67b32f5131fbd927888 /core/mouse.zig | |
| parent | 3d60aa05ec1a6f9ed535186be6c6c2850c71b24d (diff) | |
| parent | d7b01dfc187244b6613a954d82552675d3bd2689 (diff) | |
| download | pardes-51f211d694beff9a389ab519f2286cef077adb81.tar.gz pardes-51f211d694beff9a389ab519f2286cef077adb81.zip | |
merge (M3): tonplrtr 3d60aa05ec1a (L2a: the tags, grips, band and notice row drawn from the chrome, the old ChromeTheme, Roles and Grounds views deleted, part H's inks, the path dim while a pane previews another file; M2's wxvzvomn, dump.load resolves the chrome; FP's PDF preview leak, the exec rerun's spawn stop, ABI 3.4's PDF hits) with rppqvrqx d7b01dfc1872 (W9, walkui UX DESIGN part O on W5's part M: the tag stays at rest and the head hangs under it as the band's first row, a picker hangs under the tag of the pane with the keyboard, the mouse never ends it, TagState.waits, Pick.tall, the act/source row gone), resolved: THE CODE: core/draw.zig joinBand draws W5/W9's layout with L2a's inks: the head (TagState.head) and the band from `p.chrome().on(focus or plain)` (its keys `inks.key`, its error `inks.severity[0]`, its dim and rule the ground's), the band's rows' keys, chords, `pre` (the name tint `chrome.name[g]`), dim, kind and matched letters as L2a drew them, W9's loop variable `i` kept; paintPaneTag keeps W9's question in the tag (TagState.asking) and L2a's single tag ink (W9's out-of-rest `text_style` gone with L2a's: a question's text and the tag's own were the same ink once Roles went), and draws the computed words in the words' ink whenever the tag does not ask (L2a's `head == null and !asks`: out of rest the tag is the rest tag now, so its words are the rest words); render's head-and-band gutter (W9's `at.tag`) on L2a's ground; draw's key-ink test reads `p.chrome().on(.focus)` and W9's `? help`; core/TagState.zig's W5 test "out of rest a tag is drawn as at rest ..." (renamed: "... but the box and its path's ink, the path its own and dim ...") lets the path's cells differ in their ink alone, the dim ink, the dimmed text ending `/far.txt`: L2a's zrxurkop dims a tag's path while its body previews another file (the coordinator's ruling, UX DESIGN M7.2), which the test, written before it on W5's tree, read as a moved cell (core-test failed it at TagState.zig:1741 on the merge as jj made it); THE GOLDENS: process-test -- --update re-recorded all 103 golden cases, the 102 golden files (every one with a frame out of rest among them), and moved exactly the two in conflict, fsearch and selregex, each now W9's text rows byte for byte (gdiff.py: no snap row differs from W9's) and L2a's inks on them; read cell by cell (.scratch/walkui/M3/gpairs.py: each cell where the merge differs from W9's recording, and whether L2a made that same move base -> L2a): selregex's four style blocks and fsearch's one move only by L2a's classes: the window and column rows to the page (#b2c3b8 on #1d2824 -> #788079 on #0d1410, the active column's #becfc4 on #314738 too), the reading pane's tint #2c2c0f gone to the focus ground #394440 under the rest tag (full ink #becfc4 -> #cadbd0, the name tint #ecc8f2 kept, its computed words and the blanks after them #becfc4 -> #a1b1a8, the word ink) and under the head on the row below it (text #cadbd0, keys #bada9d -> #add38a bold, dim #79836f -> #8e9d94), a focused reading grip's glyph #000000 -> mode_glyph #06779d, the rail's current tick to the current hit #917a53, a command pane's computed words #b2c3b8 -> #819188; the only pairs L2a's own recordings never made are the same ink moves on cells W9 newly drew there: the head row's gutter cells on the tag's ground (`d` and the body's #e5eee5 on #2c2c0f -> #394440: render's gutter fill on L2a's ground), and fsearch's rest tag on the reading pane W9 moved to row 16 (name tint and words as selregex's); no row neither side explains; the 100 other golden files re-recorded byte for byte as the merge had them (L2a's 36 as L2a recorded them, W9's six text-only goldens as W9 did); GATES (Debug tui, on this change): core-test 1163/1338 (175 skipped; L2a's tree 1160/1335, W9's three new tests), shell-test 1386/1389 (3 skipped), process-test 0 of 103 failed with --update (2 moved, read above); the rest of the gates on the stack's top; load 1.2 to 2.5
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.zig | 371 |
1 files changed, 317 insertions, 54 deletions
diff --git a/core/mouse.zig b/core/mouse.zig index 04bbaeb4..dc730923 100644 --- a/core/mouse.zig +++ b/core/mouse.zig @@ -503,16 +503,22 @@ fn chordCutPaste(p: *Pardes, cut: bool) edit.Error!void { pub fn handleMouse(p: *Pardes, event: Mouse) void { const v = p.view(); - // A click that gives the keyboard to another pane ends the level or - // typing state of the tag out of rest as Esc does, its text's prefix - // with it (SPEC §3.4.6: only the pane with the keyboard leaves rest); - // one in its band or its own tag keeps it. + // The mouse never ends a state as a side effect (UX DESIGN O2): an + // event that gives the keyboard to another pane leaves a state with a + // field (Help, a picker, a text prompt, `:`, rename) up, waiting for it + // (TagState.waits); a level, the registers or describe-key, which hold + // no typed text, end as Esc ends them, the text's prefix with them + // (SPEC §3.4.6). The pointer's motion and the wheel move no keyboard. const host = pardes.TagState.hostOf(p); defer if (host) |was| if (v.active != was) { - const to = v.active; - v.active = was; - pardes.TagState.toRest(p); - v.active = to; + if (v.tag_state.kind != .rest and v.tag_state.kind != .describe) { + v.tag_state.waits = true; + } else { + const to = v.active; + v.active = was; + pardes.TagState.toRest(p); + v.active = to; + } }; var m = event; // A click goes somewhere else: the question it leaves unanswered is @@ -611,6 +617,13 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void { return; } + // B1 off the head and the band gives the keyboard where it gives it at + // rest (a tag's text, a body, a header): a state with a field waits for + // it; a level, the registers and describe-key end first (UX DESIGN O2). + // B1 on them gives it back (bandPress). + if (m.kind == .press and m.button == config.select_button and host != null and bandPoint(p, mcol, mrow) == null) { + if (v.tag_state.kind != .rest and v.tag_state.kind != .describe) v.tag_state.waits = true else pardes.TagState.toRest(p); + } const hovered = paneAt(p, mcol, mrow); // any press that is NOT the execute+select chord abandons a pending @@ -726,7 +739,14 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void { if (m.kind == .press) { tagline.exitHeader(p); } - if (m.kind == .press) if (bandPoint(p, mcol, mrow)) |point| return bandPress(p, m.button, point); + if (m.kind == .press) if (bandPoint(p, mcol, mrow)) |point| return bandPress(p, m, point); + // B2 or B3 on the text a picker previews lands it first, as Enter + // does: acting on that file is taking it (UX DESIGN O3); the press then + // does what it does at rest, in the file landed. + if (m.kind == .press and (m.button == config.exec_button or m.button == config.look_button)) if (hovered) |id| if (pardes.Pick.previewsAt(p, id, mrow)) { + pardes.Pick.landHere(p); + p.layOut(); + }; switch (m.button) { .none, .back, .forward => {}, // hover and navigation handled above @@ -920,77 +940,100 @@ 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). +/// 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 -/// the rows' cursor on the row it is on; execute runs the word under it -/// and look looks at it, as on a tag, the tag back at rest first. -fn bandPress(p: *Pardes, button: Mouse.Button, point: BandPoint) void { +/// A press on a band (Band.zig), read-only text, and the wheel over it +/// (UX DESIGN O2). The select button gives a state waiting for the +/// keyboard its keyboard back (TagState.waits), puts the field's caret +/// where it is in the head's field, and the rows' cursor on the row it is +/// on. Execute runs the word under it and look looks at it, as on a tag: a +/// level back at rest first, a state with a field kept up (what the word +/// does may end it: Pick.yieldFor); B3 on a picker's row is Enter there, +/// Shift-B3 S-Enter. The wheel moves a picker's cursor or Help's. +fn bandPress(p: *Pardes, m: Mouse, 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. + const s = &v.tag_state; + const field = s.kind != .rest and s.kind != .describe; + if (m.button == .wheel_up or m.button == .wheel_down) { + const delta = if (m.button == .wheel_up) -config.wheel_rows else config.wheel_rows; + if (s.kind == .pick) pardes.Pick.wheel(p, delta); + if (s.kind == .help and s.nhits > 0) s.rows.at = @intCast(std.math.clamp(@as(i32, s.rows.at) + delta, 0, @as(i32, s.nhits) - 1)); + return; + } + if (m.button == config.select_button and s.waits) { + s.waits = false; + v.active = point.id; + p.panes[point.id].?.focus = .body; + } + // 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) { - 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 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 (m.button == config.select_button) { + const caret = h.caret orelse return; + const at = shown.toReal(modal.lineStartOffset(shown.text, point.line) + modal.graphemeStart(text, raw)); + const start = caret - s.field.caret; + if (at >= start and at <= start + s.field.len) s.field.caret = @intCast(at - start); + return; + } + if (m.button != config.exec_button and m.button != config.look_button) 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); - pardes.TagState.toRest(p); - return exec.runBuiltin(p, if (button == config.exec_button) config.exec_cmd else config.look_cmd, v.active, "", word); + if (!field) pardes.TagState.toRest(p); + return exec.runBuiltin(p, if (m.button == config.exec_button) config.exec_cmd else config.look_cmd, point.id, "", word); } - if (button == config.select_button) { - const band = (pardes.Band.of(p, arena, p.panes[point.id].?, point.id) catch return) orelse return; - const ln = band.line(arena, p.settings.tab, point.line) catch return; + const band = (pardes.Band.of(p, arena, p.panes[point.id].?, point.id) catch return) orelse return; + const ln = band.line(arena, p.settings.tab, point.line) catch return; + if (m.button == config.select_button) { for (ln.parts) |part| if (point.col >= part.col -| 2 and point.col < part.col + part.width) { - pardes.TagState.point(p, part.row.index); + if (s.kind == .pick) pardes.Pick.press(p, part.row, false, false) else pardes.TagState.point(p, part.row.index); }; return; } - if (button != config.exec_button and button != config.look_button) return; - const word = (pardes.Band.wordAt(p, arena, point.id, point.line, point.col) catch return) orelse return; - const kept = arena.dupe(u8, word) catch return; - // A picker's band: B2 runs the word with the picker live (an act's word - // acts, Pick.execWord); B3 on a row lands on it. - if (v.tag_state.kind == .pick) { - if (button == config.exec_button) return exec.runBuiltin(p, config.exec_cmd, v.active, "", kept); - const band = (pardes.Band.of(p, arena, p.panes[point.id].?, point.id) catch return) orelse return; - const ln = band.line(arena, p.settings.tab, point.line) catch return; - for (ln.parts) |part| if (point.col >= part.col and point.col < part.col + part.width) { - pardes.TagState.point(p, part.row.index); - return pardes.Pick.landHere(p); + if (m.button != config.exec_button and m.button != config.look_button) return; + // A picker's band: B3 on a row is Enter there (Pick.press); B2 runs the + // word under it with the picker up (an act's word acts, Pick.execWord). + if (s.kind == .pick and m.button == config.look_button) { + for (ln.parts) |part| if (point.col >= part.col -| 2 and point.col < part.col + part.width) { + return pardes.Pick.press(p, part.row, true, m.shift); }; return; } - pardes.TagState.toRest(p); - exec.runBuiltin(p, if (button == config.exec_button) config.exec_cmd else config.look_cmd, v.active, "", kept); + const word = (pardes.Band.wordAt(p, arena, point.id, point.line, point.col) catch return) orelse return; + const kept = arena.dupe(u8, word) catch return; + if (s.kind != .pick) pardes.TagState.toRest(p); + exec.runBuiltin(p, if (m.button == config.exec_button) config.exec_cmd else config.look_cmd, point.id, "", kept); } /// Index of the pane pair in column `c` whose seam (see seamRowOf) is screen @@ -2036,3 +2079,223 @@ test "one column's words at the window row's left and the window's at its right clickAt(p, .middle, row.words + @as(u16, "Find Grep ".len) + 2, 0); try std.testing.expectEqual(@as(usize, 2), p.view().ncol); } + +/// A picker asked from a held pane with three places in `dir`'s files, +/// previewed in a reader made under it (UX DESIGN O1): the asker's id. +fn heldPicker(p: *Pardes, tmp: *std.testing.TmpDir) !usize { + for ([_][]const u8{ "one.zig", "two.zig", "three.zig" }) |name| try tmp.dir.writeFile(std.testing.io, .{ .sub_path = name, .data = "const a = 1;\nconst b = 2;\nconst c = 3;\nconst d = 4;\n" }); + var buf: [std.Io.Dir.max_path_bytes]u8 = undefined; + const dir = buf[0..try tmp.dir.realPath(std.testing.io, &buf)]; + _ = try p.setTestFile("held\n"); + const held = p.view().active; + pardes.Trail.keep(p.panes[held].?); + var rows: [3 * (std.Io.Dir.max_path_bytes + 32)]u8 = undefined; + const list = try std.fmt.bufPrint(&rows, "{s}/one.zig:2:1 Wrap b\n{s}/two.zig:3:1 c\n{s}/three.zig:4:1 d\n", .{ dir, dir, dir }); + pardes.Pick.open(p, held, .list, "Refs", "", list); + p.update(.tick); + p.sync(); + return held; +} + +/// Screen row `i` of the band under pane `id`'s head, and a column on its +/// rows' text. +fn bandRow(p: *Pardes, id: usize, i: u16) [2]u16 { + const r = p.view().rects[id]; + const at = pardes.Band.covered(p, p.panes[id].?, id); + return .{ r.x + TAG_TEXT_INSET + 8, r.y + at.tag + at.head + i }; +} + +test "the mouse never ends a picker as a side effect (UX DESIGN O2): the pointer's motion and the wheel anywhere leave it up; the wheel over its rows moves its cursor `wheel_rows` and the preview follows; B1 on a row puts the cursor there and keeps the keyboard in the field; B2 or B3 on the preview's text lands it first; Shift-B3 on a row opens it below" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 40 }); + defer p.deinit(); + p.settings.jumps = .walk; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + const held = try heldPicker(p, &tmp); + const pk = pardes.Pick.live(p).?; + const reader = p.paneBySerial(pk.landing).?; + try std.testing.expect(reader != held and pk.made); + const s = &p.view().tag_state; + const rr = p.view().rects[reader]; + // Motion and the wheel over the reader, over the held pane's body, and + // over the window row: nothing ends. + for ([_][2]u16{ .{ rr.x + 6, rr.y + 3 }, .{ 6, 0 } }) |at| { + p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = at[0], .row = at[1] } }); + p.update(.{ .mouse = .{ .button = .wheel_down, .kind = .press, .col = at[0], .row = at[1] } }); + try std.testing.expect(pardes.Pick.live(p) == pk and !s.waits); + } + try std.testing.expectEqual(held, p.view().active); + // The wheel over the rows: the cursor down, the next row previewed on + // the frame after. + const row0 = bandRow(p, held, 0); + p.update(.{ .mouse = .{ .button = .wheel_down, .kind = .press, .col = row0[0], .row = row0[1] } }); + try std.testing.expectEqual(@as(u16, config.wheel_rows), s.rows.at); + p.update(.tick); + try std.testing.expect(std.mem.endsWith(u8, p.panes[reader].?.file.?.path, "two.zig")); + p.update(.{ .mouse = .{ .button = .wheel_up, .kind = .press, .col = row0[0], .row = row0[1] } }); + try std.testing.expectEqual(@as(u16, 0), s.rows.at); + // B1 on the third row: the cursor there, the picker up, the keyboard + // its field's. + const row2 = bandRow(p, held, 2); + clickAt(p, .left, row2[0], row2[1]); + try std.testing.expect(pardes.Pick.live(p) == pk and !s.waits); + try std.testing.expectEqual(@as(u16, 2), s.rows.at); + try std.testing.expectEqual(held, p.view().active); + p.update(.{ .key = .{ .cp = pardes.Key.up } }); + try std.testing.expectEqual(@as(u16, 1), s.rows.at); + p.update(.{ .key = .{ .cp = pardes.Key.down } }); + p.update(.tick); + p.sync(); + // B3 on the preview's text: it lands first, the held pane's reader + // showing that file at that line, the picker gone. + const r2 = p.view().rects[reader]; + try std.testing.expect(std.mem.endsWith(u8, p.panes[reader].?.file.?.path, "three.zig")); + clickAt(p, .right, r2.x + config.GUTTER + 6, r2.y + p.panes[reader].?.tag_rows); + try std.testing.expect(pardes.Pick.live(p) == null); + const landed = pardes.Trail.readerOf(p, p.panes[held].?).?; + try std.testing.expect(std.mem.endsWith(u8, p.panes[landed].?.file.?.path, "three.zig")); + // Shift-B3 on a row: that place in a new pane below. + p.view().active = held; + var n: usize = 0; + for (p.panes) |slot| n += @intFromBool(slot != null); + pardes.Pick.open(p, held, .list, "Refs", "", pk.rows); + p.sync(); + const first = bandRow(p, held, 0); + p.update(.{ .mouse = .{ .button = .right, .kind = .press, .col = first[0], .row = first[1], .shift = true } }); + p.update(.{ .mouse = .{ .button = .right, .kind = .release, .col = first[0], .row = first[1], .shift = true } }); + try std.testing.expect(pardes.Pick.live(p) == null); + var now: usize = 0; + for (p.panes) |slot| now += @intFromBool(slot != null); + try std.testing.expectEqual(n + 1, now); + try std.testing.expect(std.mem.endsWith(u8, p.panes[p.view().active].?.file.?.path, "one.zig")); +} + +test "B1 in another pane: a picker waits (UX DESIGN O2), unrolled as it was, its box its pane's mode and no caret in its field; keys go where the keyboard is; B1 on its head, or C-w back to its pane, gives it the keyboard; Esc anywhere ends it first, then the pane's own Esc" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 40 }); + defer p.deinit(); + p.settings.jumps = .walk; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + const held = try heldPicker(p, &tmp); + const pk = pardes.Pick.live(p).?; + const reader = p.paneBySerial(pk.landing).?; + const s = &p.view().tag_state; + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + const a = frame.allocator(); + // B1 on the preview: the keyboard there, the picker waiting. + const rr = p.view().rects[reader]; + clickAt(p, .left, rr.x + config.GUTTER + 3, rr.y + p.panes[reader].?.tag_rows + 1); + try std.testing.expectEqual(reader, p.view().active); + try std.testing.expect(pardes.Pick.live(p) == pk and s.waits); + try std.testing.expectEqual(@as(?usize, held), pardes.TagState.hostOf(p)); + const surface = try p.render(a); + const hr = p.view().rects[held]; + try std.testing.expectEqualStrings(config.tag_normal, surface.at(hr.x, hr.y).grapheme()); + try std.testing.expect(surface.cursor == null or surface.cursor.?.y >= rr.y); + // A key goes to the reader: `j` moves its caret, the field untouched. + const row = p.panes[reader].?.body.cur_row; + p.update(.{ .key = .{ .cp = 'j', .text = "j" } }); + try std.testing.expectEqual(row + 1, p.panes[reader].?.body.cur_row); + try std.testing.expectEqual(@as(u16, 0), s.field.len); + // B1 on the head: the keyboard back in the field. + const head = bandRow(p, held, 0); + clickAt(p, .left, head[0], head[1] - 1); + try std.testing.expect(!s.waits and p.view().active == held); + p.update(.{ .key = .{ .cp = 'w', .text = "w" } }); + try std.testing.expectEqualStrings("w", s.field.text()); + // C-w to the held pane from the reader gives it back too. + clickAt(p, .left, rr.x + config.GUTTER + 3, rr.y + p.panes[reader].?.tag_rows + 1); + try std.testing.expect(s.waits); + p.update(.{ .key = .{ .cp = 'w', .ctrl = true } }); + p.update(.{ .key = .{ .cp = 'k', .text = "k" } }); + p.update(.{ .key = .{ .cp = pardes.Key.enter } }); + try std.testing.expect(!s.waits and p.view().active == held and pardes.Pick.live(p) == pk); + // The keyboard to the held pane's own text under the band, in insert + // mode; Esc ends the picker first, the text still inserting; the next + // Esc is the text's. + const at = pardes.Band.covered(p, p.panes[held].?, held); + clickAt(p, .left, hr.x + config.GUTTER + 3, hr.y + at.tag + at.over); + try std.testing.expect(s.waits and p.view().active == held); + p.update(.{ .key = .{ .cp = 'i', .text = "i" } }); + try std.testing.expect(p.panes[held].?.body.mode == .insert); + p.update(.{ .key = .{ .cp = pardes.Key.escape } }); + try std.testing.expect(pardes.Pick.live(p) == null and s.kind == .rest and !s.waits); + try std.testing.expect(p.panes[held].?.body.mode == .insert); + p.update(.{ .key = .{ .cp = pardes.Key.escape } }); + try std.testing.expect(p.panes[held].?.body.mode == .normal); +} + +test "B1 on the asking pane's own tag: the picker waits, the tag's text has the keyboard; a word there that changes nothing leaves it up; B2 Del ends it first, as Esc does, and closes the pane (UX DESIGN O2, O3)" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 40 }); + defer p.deinit(); + p.settings.jumps = .walk; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + const held = try heldPicker(p, &tmp); + const s = &p.view().tag_state; + p.panes[held].?.tag.own = try p.gpa.dupe(u8, "Wrap"); + p.sync(); + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + const tag = try tagline.tagText(p, frame.allocator(), p.panes[held].?); + const hr = p.view().rects[held]; + const col = struct { + fn of(q: *Pardes, t: []const u8, x: u16, word: []const u8) u16 { + return x + TAG_TEXT_INSET + 1 + @as(u16, @intCast(panes.File.displayWidth(q.settings.tab, t[0..std.mem.indexOf(u8, t, word).?]))); + } + }.of; + clickAt(p, .left, col(p, tag, hr.x, "Wrap"), hr.y); + try std.testing.expect(pardes.Pick.live(p) != null and s.waits); + try std.testing.expectEqual(Pane.Focus.tag, p.panes[held].?.focus); + const wrapped = p.settings.wrap; + clickAt(p, .middle, col(p, tag, hr.x, "Wrap"), hr.y); + try std.testing.expect(p.settings.wrap != wrapped and pardes.Pick.live(p) != null); + var n: usize = 0; + for (p.panes) |slot| n += @intFromBool(slot != null); + clickAt(p, .middle, col(p, tag, hr.x, "Del"), hr.y); + try std.testing.expect(pardes.Pick.live(p) == null and s.kind == .rest); + try std.testing.expect(p.panes[held] == null); + var now: usize = 0; + for (p.panes) |slot| now += @intFromBool(slot != null); + // The held pane and the reader made for the picker, both gone. + try std.testing.expectEqual(n - 2, now); +} + +test "the act step and the rows under the mouse (UX DESIGN O2): B2 on an act's word acts and the picker stays, B2 on a row's word runs it and the picker stays, B1 on an act puts the act step's cursor on it" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 40 }); + defer p.deinit(); + p.settings.jumps = .walk; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + const held = try heldPicker(p, &tmp); + const pk = pardes.Pick.live(p).?; + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + const a = frame.allocator(); + // B2 on `Wrap` in the first row's text. + const band = (try pardes.Band.of(p, a, p.panes[held].?, held)).?; + const ln = try band.line(a, p.settings.tab, 0); + const r = p.view().rects[held]; + const top = bandRow(p, held, 0)[1]; + const wrap_col: u16 = r.x + TAG_TEXT_INSET + @as(u16, @intCast(panes.File.displayWidth(p.settings.tab, ln.text[0..std.mem.indexOf(u8, ln.text, "Wrap").?]))) + 1; + const wrapped = p.settings.wrap; + clickAt(p, .middle, wrap_col, top); + try std.testing.expect(p.settings.wrap != wrapped and pardes.Pick.live(p) == pk); + // M-l: the act step; B1 on `Copy` puts its cursor there, B2 on it + // copies the place, the picker up. + p.update(.{ .key = .{ .cp = 'l', .alt = true } }); + _ = frame.reset(.retain_capacity); + const acts = (try pardes.Band.of(p, a, p.panes[held].?, held)).?; + var copy: ?[2]u16 = null; + for (0..acts.height) |y| { + const l = try acts.line(a, p.settings.tab, @intCast(y)); + if (std.mem.indexOf(u8, l.text, "y Copy")) |at| copy = .{ r.x + TAG_TEXT_INSET + @as(u16, @intCast(panes.File.displayWidth(p.settings.tab, l.text[0..at]))) + 3, top + @as(u16, @intCast(y)) }; + } + clickAt(p, .left, copy.?[0], copy.?[1]); + try std.testing.expect(pk.spine == .acts and pardes.Pick.live(p) == pk); + try std.testing.expectEqual(@as(u8, 6), pk.act_at); + clickAt(p, .middle, copy.?[0], copy.?[1]); + try std.testing.expect(pardes.Pick.live(p) == pk); + try std.testing.expect(std.mem.endsWith(u8, p.registers.text(p.gpa, pardes.Registers.default).?, "one.zig:2\n")); +} |
