diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-06 02:56:53 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-06 04:13:33 -0300 |
| commit | d1d5d3cfb18841604bba2057eeb3598f729b4475 (patch) | |
| tree | 298c29ab8767852bf74eb86ad4d15acc4348f109 /src/look.zig | |
| parent | 33037ece5af9ae1c7048819bbbae3fc5e6fc4ade (diff) | |
| download | pardes-d1d5d3cfb18841604bba2057eeb3598f729b4475.tar.gz pardes-d1d5d3cfb18841604bba2057eeb3598f729b4475.zip | |
client #1, the views indexed: a view's share of the session is Pardes.View (the ~42 fields views.fields named: size, cell metrics, columns, rects, focus, jumps, pointer, gestures, prefixes, frontend), one of Pardes.views[4] (null when closed), the live one views[live] through Pardes.view() (index field `view` renamed `live`); going into another view is the index plus the panes' shares, which stay swapped (park and unpark now move only Pane.pv); views.zig loses fields, Part over Pardes, Parked, kept, emptied and the session half of every copy, and a pane closing leaves every view's layout at once (views.gone, at the two places a slot is freed) instead of the serials each parked view kept; drawOne and within put the drawn view's own share back whole; the views are in the digest now (tape's per-field parts name views[k].field), so a fresh view's col_x/col_w default to zeros, not undefined; the dump keeps every open view in the core and the panes' shares of the others under `shares`; an image from before (live view as the core's own fields, the rest under `views`) loads them into views[] once; the ~2,400 references rewritten mechanically from the compiler's errors (p.active is p.view().active, `const v = p.view()` hoisted in 823 places), Kind.zig (4 lines) and addon_test.zig (3) among them, macos.zig by pattern (not compiled here); tape's watched host writes read the live view's frontend and active; perf.zig's accessor lines change its harness hash, the debug baselines re-keyed to it (their numbers the base's); no golden changes; gates: core-test 956/956 both, unit-test 1487/1488 tui and 1530/1531 gui, behaviour-test 248/248 both, pane-test 171/172, snap all 105 ok, process-test 0 of 37 failed tui, replicas ok
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/look.zig')
| -rw-r--r-- | src/look.zig | 170 |
1 files changed, 88 insertions, 82 deletions
diff --git a/src/look.zig b/src/look.zig index 7af69c55..b2fb5ae9 100644 --- a/src/look.zig +++ b/src/look.zig @@ -445,7 +445,7 @@ pub fn armLookWalk(p: *Pardes, id: usize) void { pub fn invalidateLookHover(p: *Pardes, id: usize) void { if (lookHoverPane(p) != id) return; - p.raw_hover_intent = false; + p.view().raw_hover_intent = false; cancelLookHover(p); } @@ -556,9 +556,9 @@ fn lookFirstHit(p: *Pardes, id: usize) void { const rid = pane.search_pane orelse return; const rp = p.panes[rid] orelse return; if ((rp.file orelse return).content.len == 0) return; - p.active = rid; + p.view().active = rid; lookWalk(p, 1); - if (p.active != rid) return; // walked out of the list; leave it there + if (p.view().active != rid) return; // walked out of the list; leave it there const txt = edit.currentSelText(p, rp) orelse return; // spent, exactly as the look chord spends it (handleKey) rp.body.vsel.active = false; @@ -656,7 +656,7 @@ pub fn searchStep(p: *Pardes, id: usize, delta: i32) bool { while (step >= 0 and step < nrows) : (step += direction) { if (!panes.Output.isResultRow(rf, @intCast(step))) continue; _ = jumpResult(p, id, @intCast(step)); - p.active = id; + p.view().active = id; break; } return true; @@ -733,10 +733,11 @@ fn lookStand(pane: *Pane) LookFrom { } fn lookWalkPanes(p: *Pardes, out: *[MAX_PANES]usize) []const usize { + const v = p.view(); var n: usize = 0; // A command pane walked from (`make`'s errors): its own places first. if (commandPaneActive(p)) { - out[0] = p.active; + out[0] = v.active; n = 1; } var i = p.n_look_src; @@ -765,8 +766,8 @@ fn lookWalkPanes(p: *Pardes, out: *[MAX_PANES]usize) []const usize { } } if (n == 0) { - if (p.panes[p.active] == null) return out[0..0]; - out[0] = p.active; + if (p.panes[v.active] == null) return out[0..0]; + out[0] = v.active; n = 1; } return out[0..n]; @@ -846,8 +847,8 @@ fn lookSpanIn(p: *Pardes, pane: *Pane, from: LookFrom, delta: i32, budget: *usiz /// A command pane has the keyboard: `n` there walks its own output. fn commandPaneActive(p: *Pardes) bool { - const pane = p.panes[p.active] orelse return false; - return pane.command != null and pane.file == null and p.header == null; + const pane = p.panes[p.view().active] orelse return false; + return pane.command != null and pane.file == null and p.view().header == null; } pub fn lookWalk(p: *Pardes, delta: i32) void { @@ -855,8 +856,8 @@ pub fn lookWalk(p: *Pardes, delta: i32) void { const order = lookWalkPanes(p, &buf); if (order.len == 0) return; // From a command pane the walk starts there, whoever walked last. - const owner = if (commandPaneActive(p)) p.active else if (p.look_walk_owner) |serial| p.paneBySerial(serial) else null; - const active_at = std.mem.indexOfScalar(usize, order, p.active) orelse 0; + const owner = if (commandPaneActive(p)) p.view().active else if (p.look_walk_owner) |serial| p.paneBySerial(serial) else null; + const active_at = std.mem.indexOfScalar(usize, order, p.view().active) orelse 0; const at = if (owner) |wanted| std.mem.indexOfScalar(usize, order, wanted) orelse active_at else @@ -884,7 +885,7 @@ fn landLookSpot(p: *Pardes, id: usize, pane: *Pane, spot: Pane.LookSpot) void { pane.body.cur_pinned = true; pane.look_at = spot; p.look_walk_owner = pane.serial; - p.active = id; + p.view().active = id; pane.ensureCursorVisible(); } @@ -931,15 +932,16 @@ fn noteLookHover(p: *Pardes, col: u16, row: u16, body_hit: ?Mouse.BodyHit, tag_h } pub fn refreshLookHoverFromRaw(p: *Pardes) void { - if (!p.pointer_inside or !p.raw_hover_intent) return; - const mapped: struct { col: u16, row: u16 } = .{ .col = p.pointer_raw_col, .row = p.pointer_raw_row }; - p.hover_col = mapped.col; - p.hover_row = mapped.row; - const body_hit: ?Mouse.BodyHit = if (p.pointer_body_hit) |mapped_hit| + const v = p.view(); + if (!v.pointer_inside or !v.raw_hover_intent) return; + const mapped: struct { col: u16, row: u16 } = .{ .col = v.pointer_raw_col, .row = v.pointer_raw_row }; + v.hover_col = mapped.col; + v.hover_row = mapped.row; + const body_hit: ?Mouse.BodyHit = if (v.pointer_body_hit) |mapped_hit| mouse.bodyHitForPane(p, mouse.paneAt(p, mapped.col, mapped.row) orelse return cancelLookHover(p), mapped_hit, false) orelse return cancelLookHover(p) else null; - noteLookHover(p, mapped.col, mapped.row, body_hit, p.pointer_tag_hit); + noteLookHover(p, mapped.col, mapped.row, body_hit, v.pointer_tag_hit); } pub fn advanceLookHover(p: *Pardes) void { @@ -991,7 +993,7 @@ pub fn advanceLookHover(p: *Pardes) void { pub fn focusPaneLine(p: *Pardes, id: usize, at: Spot, landing: enum { center, keep }) void { if (id >= MAX_PANES) return; const pane = p.panes[id] orelse return; - p.active = id; + p.view().active = id; if (pane.collapsed) layout.toggleCollapse(p, id); pane.body.normal.clear(); if (pane.hasPdf()) { @@ -1056,6 +1058,7 @@ fn focusPaneByPath(p: *Pardes, path: []const u8, at: Spot) bool { /// Navigation starts a new selection at the destination. pub fn clearNavigationSelection(p: *Pardes, pane: *Pane) void { + const v = p.view(); pane.body.vsel = .{}; pane.body.nsel = 0; pane.body.select = false; @@ -1068,12 +1071,13 @@ pub fn clearNavigationSelection(p: *Pardes, pane: *Pane) void { state.clearDrag(); state.clearSelection(p.pdf_gpa); }; - if (p.drag == .select and p.panes[p.drag.select.id] == pane) p.drag = .none; + if (v.drag == .select and p.panes[v.drag.select.id] == pane) v.drag = .none; } /// Resolve without changing focus or falling back to search. PDF links use /// the same location rules as an ordinary Look before offering a choice. fn resolveLookTarget(p: *Pardes, id: usize, txt: []const u8, realbuf: *[4096]u8) Target { + const v = p.view(); const trimmed = std.mem.trim(u8, txt, " \t\r\n"); const pl = parsePathLine(trimmed); if (pl.path.len > 0) if (openPaneTarget(p, pl.path, pl.at)) |target| return target; @@ -1081,8 +1085,8 @@ fn resolveLookTarget(p: *Pardes, id: usize, txt: []const u8, realbuf: *[4096]u8) var seen: [MAX_PANES][]const u8 = undefined; var nseen: usize = 0; var n: usize = 0; - cand: while (n <= p.jumps.n) : (n += 1) { - const k: usize = if (n == 0) id else p.jumps.list[p.jumps.n - n].pane; + cand: while (n <= v.jumps.n) : (n += 1) { + const k: usize = if (n == 0) id else v.jumps.list[v.jumps.n - n].pane; if (n > 0 and k == id) continue; // tried first, skip the rerun const op = p.panes[k] orelse continue; const dir = Pardes.paneDir(op); @@ -1180,7 +1184,7 @@ pub fn followPdfLink(p: *Pardes, id: usize, probe: *const panes.Pdf.WordProbe) v .internal => |dest| { p.noteHaptic(.look); noteLookSource(p, id); - p.active = id; + p.view().active = id; panes.Pdf.revealOutlineDestination(p, pane, dest); }, .external => lookAt(p, id, target), @@ -1303,11 +1307,11 @@ fn missed(p: *Pardes, id: usize, comptime fmt: []const u8, args: anytype) void { /// nothing, leaves no pane it opened, and is a miss; a bare line number /// selects the line, its newline included, as acme's does. fn settleLine(p: *Pardes, id: usize, path: []const u8, at: Spot, before: usize, opened: ?usize) void { - const shown = p.panes[p.active] orelse return; + const shown = p.panes[p.view().active] orelse return; const f = if (shown.file) |*file| file else return; if (at.line > panes.File.nlines(p.gpa, f)) { if (opened) |free| p.removePane(free, null) catch {}; - if (p.panes[before] != null) p.active = before; + if (p.panes[before] != null) p.view().active = before; return missedLine(p, id, path, at.line); } if (at.line > 0 and at.col == 0 and at.end_line == 0) { @@ -1332,7 +1336,7 @@ fn lookWord(p: *Pardes, id: usize, pane: *Pane, word: []const u8) void { }); clearNavigationSelection(p, pane); ninep_pane.setDot(pane, .{ .q0 = @intCast(at), .q1 = @intCast(at + word.len) }); - p.active = id; + p.view().active = id; } /// `file:addr` or `:addr`, acme's look.c:450-543: a colon followed by an @@ -1445,6 +1449,7 @@ test "a commit hash is 7 to 40 lowercase hex digits with a letter and a digit" { /// and selects what `expr` addresses there from its dot. An address that /// does not evaluate moves nothing and says why (acme: no jump). fn lookAddress(p: *Pardes, id: usize, path: []const u8, expr: []const u8) void { + const v = p.view(); const ninep_pane = @import("ninep/pane.zig"); const Addr = @import("ninep/addr.zig").Addr; var target = id; @@ -1464,11 +1469,11 @@ fn lookAddress(p: *Pardes, id: usize, path: []const u8, expr: []const u8) void { // is looked for, as `zzq:2` is, and a miss quotes it as written. if (!by_serial and resolveLookTarget(p, id, path, &realbuf) == .none) return lookUnresolved(p, id, p.panes[id] orelse return, path.ptr[0 .. path.len + 1 + expr.len], path.ptr[0 .. path.len + 1 + expr.len]); - const before = p.active; + const before = v.active; const failures = p.fs.failures; const was_missed = p.look_missed; lookAt(p, id, path); - target = p.active; + target = v.active; // Look said why it opened nothing (its placement refused, say): // that one failure is the look's, no miss of the address after it. if (p.fs.failures != failures or (p.look_missed and !was_missed)) return; @@ -1501,7 +1506,7 @@ fn lookAddress(p: *Pardes, id: usize, path: []const u8, expr: []const u8) void { const place = std.fmt.bufPrint(&placed, "{s}:{d}", .{ name, line }) catch name; if (!opened_here) return missedLine(p, target, place, line); p.removePane(target, null) catch {}; - if (p.panes[id] != null) p.active = id; + if (p.panes[id] != null) v.active = id; return missedLine(p, id, place, line); } else |_| {} if (opened_here) return closeAndMiss(p, id, target, name, a.err); @@ -1514,7 +1519,7 @@ fn lookAddress(p: *Pardes, id: usize, path: []const u8, expr: []const u8) void { } clearNavigationSelection(p, pane); ninep_pane.setDot(pane, r); - p.active = target; + v.active = target; } /// A PDF's address is its page: `:N` turns to page N, one past its last a @@ -1536,14 +1541,14 @@ fn lookPdfPage(p: *Pardes, id: usize, target: usize, pv: *panes.Pdf.State, expr: const pane = p.panes[target].?; clearNavigationSelection(p, pane); if (pv.focusLocation(p.pdf_gpa, page, hit)) panes.Pdf.resetPageChrome(pane); - p.active = target; + p.view().active = target; } fn closeAndMiss(p: *Pardes, id: usize, opened: usize, name: []const u8, why: []const u8) void { var kept: [miss_path_cap + "…".len]u8 = undefined; @memcpy(kept[0..name.len], name); p.removePane(opened, null) catch {}; - if (p.panes[id] != null) p.active = id; + if (p.panes[id] != null) p.view().active = id; missed(p, id, "{s}: {s}", .{ kept[0..name.len], why }); } @@ -1593,7 +1598,7 @@ fn spotAt(text: []const u8, q: u32) struct { line: usize, col: usize } { /// still fit. pub fn reopenAt(p: *Pardes, from: usize, path: []const u8, at: Spot) void { lookAt(p, from, path); - const id = p.active; + const id = p.view().active; const pane = p.panes[id] orelse return; // A PDF's place is its page, the last if it has fewer now. if (comptime pdf_enabled) if (pane.pdf) |pv| if (std.mem.eql(u8, pv.path, path)) { @@ -1709,6 +1714,7 @@ fn diffLineAddress(p: *Pardes, pane: *Pane, operand: []const u8, buf: []u8) ?[]c } pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void { + const v = p.view(); const pane = p.panes[id] orelse return; // `~/x`, `~/x:12`, `~/x:/re/`: home, before anything reads the text. // Anything else as written: a look of ` return x` is of those blanks @@ -1733,7 +1739,7 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void { var diff_buf: [4096 + 32]u8 = undefined; const looked: []const u8 = diffLineAddress(p, pane, operand_raw, &diff_buf) orelse looked: { if (config.commandWord(command)) |cmd| { - if (exec.execute(p, id, cmd)) |dst| p.active = dst; + if (exec.execute(p, id, cmd)) |dst| v.active = dst; return; } break :looked operand; @@ -1801,7 +1807,7 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void { }; // A directory's pane, looked at again: read again. if (target.file) |f| if (f.listing != null) return panes.Dir.show(p, id, t.id); - const before = p.active; + const before = v.active; clearNavigationSelection(p, target); focusPaneLine(p, t.id, t.at, .center); settleLine(p, id, trimmed, t.at, before, null); @@ -1843,7 +1849,7 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void { if (target.at.line > panes.File.nlines(p.gpa, f)) return missedLine(p, id, target.path, target.at.line); // focus an existing pane on this path (rescrolled), else open - const before = p.active; + const before = v.active; var opened: ?usize = null; if (!focusPaneByPath(p, target.path, target.at)) { // A .diff or .patch looked at bare: its hunks stacked in a @@ -1854,7 +1860,7 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void { if (filesystem.read(p, target.path)) |bytes| { defer p.gpa.free(bytes); if (panes.Output.openDiff(p, id, target.path, bytes)) |hid| { - p.active = hid; + v.active = hid; return; } else |_| {} } else |_| {}; @@ -1868,7 +1874,7 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void { // miss of its line too. if (p.fs.failures != failures) return; layout.compute(p); - nt.file.?.scroll -|= @max(1, p.rects[free].h -| BOX_H) / 2; + nt.file.?.scroll -|= @max(1, v.rects[free].h -| BOX_H) / 2; if (target.at.end_line != 0) { const centered = nt.file.?.scroll; selectSpan(p, nt, target.at); @@ -1918,15 +1924,15 @@ test "Look hover waits without mutating the pane and input cancels it" { var frame = std.heap.ArenaAllocator.init(gpa); defer frame.deinit(); _ = try p.render(frame.allocator()); - const rect = p.rects[p.active]; + const rect = p.view().rects[p.view().active]; const word_x = rect.x + config.GUTTER + config.PREFIX_W + 7; const body_y = rect.y + BOX_H; const motion = Event{ .mouse = .{ .button = .none, .kind = .motion, .col = word_x, .row = body_y } }; const selections_before = pane.sel; - const active_before = p.active; + const active_before = p.view().active; const cursor_before = .{ pane.body.cur_row, pane.body.cur_col }; - const jumps_before = .{ p.jumps.n, p.jumps.cur, p.n_look_src }; + const jumps_before = .{ p.view().jumps.n, p.view().jumps.cur, p.n_look_src }; const effects_before = p.effects_len; p.update(motion); @@ -1951,9 +1957,9 @@ test "Look hover waits without mutating the pane and input cancels it" { // Resolving and displaying the operand is observational only. try std.testing.expect(std.meta.eql(selections_before, pane.sel)); - try std.testing.expectEqual(active_before, p.active); + try std.testing.expectEqual(active_before, p.view().active); try std.testing.expectEqual(cursor_before, .{ pane.body.cur_row, pane.body.cur_col }); - try std.testing.expectEqual(jumps_before, .{ p.jumps.n, p.jumps.cur, p.n_look_src }); + try std.testing.expectEqual(jumps_before, .{ p.view().jumps.n, p.view().jumps.cur, p.n_look_src }); try std.testing.expectEqual(effects_before, p.effects_len); _ = frame.reset(.retain_capacity); @@ -1966,7 +1972,7 @@ test "Look hover waits without mutating the pane and input cancels it" { p.update(.{ .output = .{ .pane = @intCast(other_id), .bytes = "busy\r\n" } }); try std.testing.expect(p.look_hover_preview != null); - const seam_x = p.col_x[0] + p.col_w[0] - 1; + const seam_x = p.view().col_x[0] + p.view().col_w[0] - 1; p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = seam_x, .row = body_y } }); p.update(.pointer_leave); try std.testing.expect(p.look_hover_wait == null); @@ -1987,7 +1993,7 @@ test "Look hover waits without mutating the pane and input cancels it" { p.look_hover_preview = .{ .col = rect.x + TAG_TEXT_INSET, .row = tag_y, - .pane = p.active, + .pane = p.view().active, .serial = pane.serial, .sel = .{ .state = .done, .c0 = 0, .c1 = 0, .r0 = 0, .r1 = 0 }, }; @@ -2042,13 +2048,13 @@ test "Look copies its operand before releasing pointer selection storage" { .rows = try p.gpa.alloc(Pane.PointerRow, 0), .raw_text = operand, }; - p.drag = .{ .select = .{ .id = 0, .button = config.select_button } }; + p.view().drag = .{ .select = .{ .id = 0, .button = config.select_button } }; lookAt(p, 0, operand); try std.testing.expectEqual(@as(i32, 2), pane.body.cur_row); try std.testing.expectEqual(@as(i32, 1), pane.body.cur_col); try std.testing.expect(pane.pointer_selections[0] == null); try std.testing.expectEqual(.none, pane.sel[0].state); - try std.testing.expectEqual(.none, p.drag); + try std.testing.expectEqual(.none, p.view().drag); } test "@p names a pane by its serial, as /index does" { @@ -2068,7 +2074,7 @@ test "Look ignores missing and out of bounds pane addresses" { for ([_][]const u8{ config.pane_addr ++ "15:2", config.pane_addr ++ "999999:2" }) |operand| { pane.body.setRange(pane.file.?.content, 0, .{ .anchor = 0, .head = 3 }, true); lookAt(p, 0, operand); - try std.testing.expectEqual(@as(usize, 0), p.active); + try std.testing.expectEqual(@as(usize, 0), p.view().active); try std.testing.expectEqual(@as(i32, 0), pane.body.cur_row); try std.testing.expect(pane.body.vsel.active); // a miss changes nothing, the selection included } @@ -2079,7 +2085,7 @@ test "a pointer resting where a look-hover found nothing does not wake the core defer p.deinit(); _ = try p.setTestFile(std.mem.asBytes(&@as([30][6]u8, @splat(" \n".*)))); p.sync(); - const r = p.rects[p.active]; + const r = p.view().rects[p.view().active]; // Resting on blanks in the body: a wait, then nothing to open. p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = r.x + 20, .row = r.y + 5 } }); var frames: usize = 0; @@ -2123,7 +2129,7 @@ const DiffFixture = struct { /// A right click's look at `row` of the diff pane (slot 0): the look /// of the address that line names. fn click(p: *Pardes, diff_pane: *Pane, row: usize) void { - p.active = 0; + p.view().active = 0; const lines = diffLines(p, diff_pane).?; var buf: [4096]u8 = undefined; p.look_missed = false; @@ -2132,7 +2138,7 @@ const DiffFixture = struct { }; fn expectAt(p: *Pardes, suffix: []const u8, line: usize) !void { - const pane = p.panes[p.active].?; + const pane = p.panes[p.view().active].?; const f = pane.file orelse return error.NoFileOpened; if (!std.mem.endsWith(u8, f.path, suffix)) { std.debug.print("opened {s}, not {s}\n", .{ f.path, suffix }); @@ -2181,26 +2187,26 @@ test "Look on each kind of diff line opens the new file at the line it names" { DiffFixture.click(p, pane, 9); try expectAt(p, "/src/a.zig", 13); DiffFixture.click(p, pane, 3); // +++ b/path: the file, a/ b/ dropped - try std.testing.expect(std.mem.endsWith(u8, p.panes[p.active].?.file.?.path, "/src/a.zig")); + try std.testing.expect(std.mem.endsWith(u8, p.panes[p.view().active].?.file.?.path, "/src/a.zig")); DiffFixture.click(p, pane, 2); // --- a/path - try std.testing.expect(std.mem.endsWith(u8, p.panes[p.active].?.file.?.path, "/src/a.zig")); + try std.testing.expect(std.mem.endsWith(u8, p.panes[p.view().active].?.file.?.path, "/src/a.zig")); try std.testing.expect(!p.look_missed); // No click: a 9P look writes a whole line, found from the cursor on. - p.active = 0; + p.view().active = 0; pane.body.cur_row = 0; lookAt(p, 0, "+line 12"); try expectAt(p, "/src/a.zig", 12); // A word on a hunk line is a word, looked for in the diff as ever. - p.active = 0; + p.view().active = 0; pane.body.cur_row = 9; lookAt(p, 0, "line"); - try std.testing.expectEqual(@as(usize, 0), p.active); + try std.testing.expectEqual(@as(usize, 0), p.view().active); // A line that is no part of a hunk is looked at as ever. - p.active = 0; + p.view().active = 0; pane.body.cur_row = 1; lookAt(p, 0, "1111111"); - try std.testing.expectEqual(@as(usize, 0), p.active); + try std.testing.expectEqual(@as(usize, 0), p.view().active); } test "Look on plain diff -u output: names as written, timestamps cut, next to the diff" { @@ -2271,12 +2277,12 @@ test "Look on a diff: headers and a hunk line's prefix are the whole line, hover defer frame.deinit(); for (points) |at| { // Back to the diff, scrolled to its top again. - p.active = 0; + p.view().active = 0; pane.file.?.scroll = 0; p.sync(); _ = frame.reset(.retain_capacity); _ = try p.render(frame.allocator()); - const rect = p.rects[0]; + const rect = p.view().rects[0]; const x = rect.x + config.GUTTER + panes.File.gutterWidth(pane) + at.col; const y = p.bodyTop(pane, rect) + at.row; // The hover's span is the click's operand. @@ -2298,11 +2304,11 @@ test "Look on a diff: headers and a hunk line's prefix are the whole line, hover p.update(.{ .mouse = .{ .button = config.look_button, .kind = .press, .col = x, .row = y } }); p.update(.{ .mouse = .{ .button = config.look_button, .kind = .release, .col = x, .row = y } }); if (at.line == 0) { - try std.testing.expectEqual(@as(usize, 0), p.active); + try std.testing.expectEqual(@as(usize, 0), p.view().active); continue; } try std.testing.expect(!p.look_missed); - if (p.active == 0) { + if (p.view().active == 0) { std.debug.print("a look at row {d} col {d} stayed in the diff\n", .{ at.row, at.col }); return error.LookStayed; } @@ -2345,14 +2351,14 @@ test "a click, a 9P whole-line look and an empty event write-back take one expan var frame = std.heap.ArenaAllocator.init(std.testing.allocator); defer frame.deinit(); for (points) |at| { - p.active = 0; + p.view().active = 0; pane.file.?.scroll = 0; pane.body.cur_row = 0; p.sync(); _ = frame.reset(.retain_capacity); _ = try p.render(frame.allocator()); // The mouse's. - const rect = p.rects[0]; + const rect = p.view().rects[0]; const x = rect.x + config.GUTTER + panes.File.gutterWidth(pane) + at.col; const y = p.bodyTop(pane, rect) + at.row; const pointed = edit.pointerTextSelection(p, 0, x, y, null, null) orelse return error.NothingPointed; @@ -2417,7 +2423,7 @@ test "every entry point to Look takes one expansion: a diff line and a file:12:5 other.body.cur_row = 0; other.body.cur_col = 0; }; - p.active = 0; + p.view().active = 0; pane.body.mode = .normal; pane.body.vsel.active = false; pane.body.cur_row = case.row; @@ -2427,7 +2433,7 @@ test "every entry point to Look takes one expansion: a diff line and a file:12:5 p.sync(); _ = frame.reset(.retain_capacity); _ = try p.render(frame.allocator()); - const rect = p.rects[0]; + const rect = p.view().rects[0]; const x0 = rect.x + config.GUTTER + panes.File.gutterWidth(pane); const y = p.bodyTop(pane, rect) + case.row; switch (entry) { @@ -2454,7 +2460,7 @@ test "every entry point to Look takes one expansion: a diff line and a file:12:5 lookAt(p, 0, p.scratch.allocator().dupe(u8, text) catch unreachable); }, } - const landed = p.panes[p.active].?; + const landed = p.panes[p.view().active].?; const f = landed.file orelse return error.NothingOpened; if (column < 0) column = landed.body.cur_col; if (!std.mem.endsWith(u8, f.path, "/src/x.zig") or landed.body.cur_row != case.line or landed.body.cur_col != column) { @@ -2516,8 +2522,8 @@ test "a tag word looked at by a click and by Enter is one record to an event rea const shown_at = std.mem.lastIndexOf(u8, shown, "Del").?; const shown_row: u16 = @intCast(std.mem.count(u8, shown[0..shown_at], "\n")); const line_start = if (std.mem.lastIndexOfScalar(u8, shown[0..shown_at], '\n')) |nl| nl + 1 else 0; - const x = p.rects[0].x + TAG_TEXT_INSET + @as(u16, @intCast(panes.File.displayWidth(shown[line_start..shown_at]))) + 1; - const y = p.rects[0].y + shown_row; + const x = p.view().rects[0].x + TAG_TEXT_INSET + @as(u16, @intCast(panes.File.displayWidth(shown[line_start..shown_at]))) + 1; + const y = p.view().rects[0].y + shown_row; p.update(.{ .mouse = .{ .button = .right, .kind = .press, .col = x, .row = y } }); p.update(.{ .mouse = .{ .button = .right, .kind = .release, .col = x, .row = y } }); var clicked_buf: [128]u8 = undefined; @@ -2555,11 +2561,11 @@ test "Incl's directories find a name found nowhere else, <name> too; bare Incl l var line: [4200]u8 = undefined; try std.testing.expect(p.executeBuiltinLine(0, try std.fmt.bufPrint(&line, "Incl {s}/inc", .{root}))); for ([_][]const u8{ "pardes_incl_probe.h", "<pardes_incl_probe.h>" }) |word| { - p.active = 0; + p.view().active = 0; p.look_missed = false; lookAt(p, 0, word); try std.testing.expect(!p.look_missed); - try std.testing.expect(std.mem.endsWith(u8, p.panes[p.active].?.file.?.path, "/inc/pardes_incl_probe.h")); + try std.testing.expect(std.mem.endsWith(u8, p.panes[p.view().active].?.file.?.path, "/inc/pardes_incl_probe.h")); } // Bare, it lists them. try std.testing.expect(p.executeBuiltinLine(0, "Incl")); @@ -2597,20 +2603,20 @@ test "LookNext in a command pane walks its own file:line places, whoever walked const cmd = p.panes[dst].?; // A walk last made elsewhere, and another pane with places in it. try std.testing.expect(p.executeBuiltinLine(0, "New")); - const scratch = p.panes[p.active].?; + const scratch = p.panes[p.view().active].?; _ = pardes.ctlfs.pane.spliceBody(p, scratch, 0, 0, "x.c:1:1 elsewhere\n") orelse return error.NoScratch; p.look_walk_owner = scratch.serial; - p.active = dst; + p.view().active = dst; cmd.focus = .body; cmd.body.mode = .normal; for ([_]u21{ 'g', 'g' }) |cp| p.update(.{ .key = .{ .cp = cp } }); - exec.runBuiltin(p, .LookNext, p.active, "", null); - try std.testing.expectEqual(dst, p.active); + exec.runBuiltin(p, .LookNext, p.view().active, "", null); + try std.testing.expectEqual(dst, p.view().active); const first = cmd.look_at orelse return error.NoSpot; const lines = try edit.paneCursorLines(p, &cmd.body); try std.testing.expect(std.mem.startsWith(u8, lines[@intCast(first.row)][@intCast(first.col0)..], "x.c:3:1")); - exec.runBuiltin(p, .LookNext, p.active, "", null); - try std.testing.expectEqual(dst, p.active); + exec.runBuiltin(p, .LookNext, p.view().active, "", null); + try std.testing.expectEqual(dst, p.view().active); const second = cmd.look_at orelse return error.NoSpot; try std.testing.expect(std.mem.startsWith(u8, lines[@intCast(second.row)][@intCast(second.col0)..], "y.c:2:1")); } @@ -2625,7 +2631,7 @@ test "Look outside a diff pane expands and looks as ever" { var frame = std.heap.ArenaAllocator.init(std.testing.allocator); defer frame.deinit(); _ = try p.render(frame.allocator()); - const rect = p.rects[0]; + const rect = p.view().rects[0]; const x = rect.x + config.GUTTER + panes.File.gutterWidth(pane) + 0; const pointed = edit.pointerTextSelection(p, 0, x, p.bodyTop(pane, rect) + 2, null, null).?; const operand = exec.operandAt(p, pane, pointed.sel, true, true); @@ -2655,7 +2661,7 @@ test "Look on a diff under each git prefix opens the repository's file, and a re try expectAt(p, c.file, 2); DiffFixture.click(p, pane, 1); // `---` try std.testing.expect(!p.look_missed); - try std.testing.expect(std.mem.endsWith(u8, p.panes[p.active].?.file.?.path, c.file)); + try std.testing.expect(std.mem.endsWith(u8, p.panes[p.view().active].?.file.?.path, c.file)); } } @@ -2687,8 +2693,8 @@ test "Look on a diff line is the look of the address it names, selected by hand: // The checkout's file, opened by a look from the diff pane. lookAt(p, 0, cargo); p.update(.tick); - try std.testing.expect(std.mem.endsWith(u8, p.panes[p.active].?.file.?.path, "Cargo.toml")); - p.active = 0; + try std.testing.expect(std.mem.endsWith(u8, p.panes[p.view().active].?.file.?.path, "Cargo.toml")); + p.view().active = 0; p.update(.tick); p.look_missed = false; if (way == 0) { @@ -2696,7 +2702,7 @@ test "Look on a diff line is the look of the address it names, selected by hand: } else { lookAt(p, 0, "entry/src/entry.rs:2"); // the same, selected by hand } - const shown = p.panes[p.active].?; + const shown = p.panes[p.view().active].?; var n: usize = 0; for (p.panes) |slot| n += @intFromBool(slot != null); seen[way] = .{ |
