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/mouse.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/mouse.zig')
| -rw-r--r-- | src/mouse.zig | 486 |
1 files changed, 248 insertions, 238 deletions
diff --git a/src/mouse.zig b/src/mouse.zig index f57bb533..7eab8322 100644 --- a/src/mouse.zig +++ b/src/mouse.zig @@ -98,29 +98,31 @@ pub const HeaderSweep = struct { /// in that text. `clamp` holds a held sweep to the header's rows and text, /// as a pane tag's sweep stays on its tag. fn headerPoint(p: *Pardes, column: ?usize, mcol: u16, mrow: u16, clamp: bool) ?struct { t: *panes.Text, text: []const u8, line: u16, at: usize } { - const t = if (column) |c| &p.col_tags[c] else &p.global_tag; - const x = if (column) |c| p.col_x[c] + TAG_TEXT_INSET else TAG_TEXT_INSET; - const focused = p.header != null and p.headerColumn() == column; + const v = p.view(); + const t = if (column) |c| &v.col_tags[c] else &p.global_tag; + const x = if (column) |c| v.col_x[c] + TAG_TEXT_INSET else TAG_TEXT_INSET; + const focused = v.header != null and p.headerColumn() == column; const text = edit.flatSurface(p, t) catch return null; const base = if (column != null) p.topBarHeight() else 0; const rows = if (column != null) layout.columnBarHeight(p) else p.topBarHeight(); const row: u16 = if (clamp) @min(mrow -| base, rows -| 1) else mrow -| base; - const top: usize = if (focused) p.header_top else 0; + const top: usize = if (focused) v.header_top else 0; const lines = modal.lineCount(text); const line: u16 = if (clamp) @intCast(@min(row + top, lines -| 1)) else @intCast(row + top); if (line > 0 and line >= lines) return null; const bar = modal.lineSlice(text, line); - const scroll = if (focused) p.header_scroll else 0; + const scroll = if (focused) v.header_scroll else 0; const kind: Layer.Kind = if (column != null) .column else .workspace; - const at = @min(bar.len, panes.File.rawAtDisplay(bar, (Layer.columnAt(p, kind, column orelse 0, p.pointer_tag_hit, clamp, row) orelse (mcol -| x)) + scroll)); + const at = @min(bar.len, panes.File.rawAtDisplay(bar, (Layer.columnAt(p, kind, column orelse 0, v.pointer_tag_hit, clamp, row) orelse (mcol -| x)) + scroll)); return .{ .t = t, .text = text, .line = line, .at = modal.lineStartOffset(text, line) + at }; } /// A header sweep's button came up: a click runs the word under it, or the /// header's selection when it is on that; a sweep runs what it swept. fn headerSweepRun(p: *Pardes, sweep: HeaderSweep) void { + const v = p.view(); const column = sweep.column(p) catch return; - const t = if (column) |c| &p.col_tags[c] else &p.global_tag; + const t = if (column) |c| &v.col_tags[c] else &p.global_tag; const text = edit.flatSurface(p, t) catch return; const swept = sweep.span(text.len); const selected = if (swept.lo < swept.hi) text[swept.lo..swept.hi] else click: { @@ -128,7 +130,7 @@ fn headerSweepRun(p: *Pardes, sweep: HeaderSweep) void { const start = modal.lineStartOffset(text, line); const bar = modal.lineSlice(text, line); const at = swept.lo - start; - const focused = p.header != null and p.headerColumn() == column; + const focused = v.header != null and p.headerColumn() == column; const on = if (focused) tagline.headerSelection(t, text, line) else null; const under = if (tagline.wordBoundsAtCol(bar, at)) |b| bar[b.lo..b.hi] else ""; break :click if (on) |sp| (if (at >= sp.lo and at < sp.hi) bar[sp.lo..sp.hi] else under) else under; @@ -143,9 +145,9 @@ fn headerSweepRun(p: *Pardes, sweep: HeaderSweep) void { if (word.len == 0) return; if (sweep.button == config.exec_button) { const named = std.meta.stringToEnum(Builtin, word); - const held = if (named) |b| (if (builtins.registry.takesArg(b)) exec.heldSelection(p, p.active) else null) else exec.heldSelection(p, p.active); - _ = exec.execute(p, p.active, exec.withArg(p, word, held)); - } else exec.runBuiltin(p, config.look_cmd, p.active, "", word); + const held = if (named) |b| (if (builtins.registry.takesArg(b)) exec.heldSelection(p, v.active) else null) else exec.heldSelection(p, v.active); + _ = exec.execute(p, v.active, exec.withArg(p, word, held)); + } else exec.runBuiltin(p, config.look_cmd, v.active, "", word); } fn clampBorderCol(lx: u16, lw: u16, rw: u16, mcol: u16) u16 { @@ -161,14 +163,14 @@ fn clampBorderRow(ay: u16, ah: u16, bh: u16, mrow: u16) u16 { } fn seamRowOf(p: *const Pardes, c: usize, k: usize) u16 { - const r = p.rects[p.cols[c].panes[k]]; + const r = p.view().rects[p.view().cols[c].panes[k]]; return r.y + r.h -| 1; } fn cornerFixture(gpa: std.mem.Allocator) !*Pardes { const p = try Pardes.init(gpa, .{ .cols = 100, .rows = 30, .shells = 3 }); p.update(.{ .resize = .{ .cols = 100, .rows = 30 } }); - p.active = p.cols[1].panes[0]; + p.view().active = p.view().cols[1].panes[0]; p.update(.{ .key = .{ .cp = 'n', .alt = true } }); // a shell below it, same column p.sync(); return p; @@ -178,9 +180,9 @@ test "a pane's last row of text is no resize handle; the rule over the next pane const p = try cornerFixture(std.testing.allocator); defer p.deinit(); const seam = seamRowOf(p, 1, 0); - const inside = p.col_x[1] + p.col_w[1] / 2; + const inside = p.view().col_x[1] + p.view().col_w[1] / 2; p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = inside, .row = seam } }); - try std.testing.expect(p.drag != .border_h); + try std.testing.expect(p.view().drag != .border_h); p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = inside, .row = seam } }); try std.testing.expect(nudgeRightSeam(p, 2) == seam + 2); } @@ -188,32 +190,32 @@ test "a pane's last row of text is no resize handle; the rule over the next pane test "a pane's grip dragged up or down its own column moves its top, down to the floor of the pane above" { const p = try cornerFixture(std.testing.allocator); defer p.deinit(); - const upper = p.cols[1].panes[0]; - const lower = p.cols[1].panes[1]; - const grip_x = p.rects[lower].x; + const upper = p.view().cols[1].panes[0]; + const lower = p.view().cols[1].panes[1]; + const grip_x = p.view().rects[lower].x; // Up, past the pane above's first row: a text pane keeps its tag, a // terminal its tag and two rows (layout.floorRows). - const top = p.rects[upper].y; + const top = p.view().rects[upper].y; const above = p.panes[upper].?; const floor: u16 = if (above.isTerminal()) above.tag_rows + layout.min_body_rows else 1; - p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = grip_x, .row = p.rects[lower].y } }); + p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = grip_x, .row = p.view().rects[lower].y } }); p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = grip_x, .row = top } }); p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = grip_x, .row = top } }); p.sync(); - try std.testing.expectEqual(floor, p.rects[upper].h); - try std.testing.expectEqual(lower, p.cols[1].panes[1]); + try std.testing.expectEqual(floor, p.view().rects[upper].h); + try std.testing.expectEqual(lower, p.view().cols[1].panes[1]); // Down, inside itself: its top follows, the pane above taking the rows. - const to = p.rects[lower].y + 6; - p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = grip_x, .row = p.rects[lower].y } }); + const to = p.view().rects[lower].y + 6; + p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = grip_x, .row = p.view().rects[lower].y } }); p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = grip_x, .row = to } }); p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = grip_x, .row = to } }); p.sync(); - try std.testing.expectEqual(to, p.rects[lower].y); + try std.testing.expectEqual(to, p.view().rects[lower].y); } fn nudgeRightSeam(p: *Pardes, delta: i32) u16 { const from = seamRowOf(p, 1, 0); - const inside = p.col_x[1] + p.col_w[1] / 2; + const inside = p.view().col_x[1] + p.view().col_w[1] / 2; const to: u16 = @intCast(@as(i32, from) + delta); // On the rule a pixel frontend draws over the lower pane's first row. p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = inside, .row = from + 1, .rule_above = true } }); @@ -229,23 +231,24 @@ pub const ChromeTarget = struct { col: u16, row: u16 }; /// on the cell, a pane's grip, a column's handle or a seam; then a cell /// away, any of a pane's tag, a handle or a seam. pub fn chromeTarget(p: *const Pardes, col: u16, row: u16) ?ChromeTarget { + const v = p.view(); if (row < p.topBarHeight() + layout.columnBarHeight(p)) return .{ .col = col, .row = row }; for ([_]u16{ 0, 1 }) |slack| { for (p.panes, 0..) |slot, id| { const pane = slot orelse continue; - const rect = p.rects[id]; + const rect = v.rects[id]; const tag = p.tagTop(pane, rect); const edge = if (slack == 0) rect.x + config.GUTTER else rect.x + rect.w; if (row >= tag and row < tag + pane.tag_rows and col >= rect.x and col < rect.x + rect.w and col < edge) return .{ .col = col, .row = row }; } - for (0..p.ncol -| 1) |column| { - const handle = p.col_x[column] + p.col_w[column] -| 1; + for (0..p.view().ncol -| 1) |column| { + const handle = v.col_x[column] + v.col_w[column] -| 1; if (@max(col, handle) - @min(col, handle) == slack) return .{ .col = handle, .row = row }; } - for (0..p.ncol) |column| { - if (col < p.col_x[column] or col >= p.col_x[column] + p.col_w[column]) continue; - for (0..p.cols[column].n -| 1) |index| { + for (0..p.view().ncol) |column| { + if (col < v.col_x[column] or col >= v.col_x[column] + v.col_w[column]) continue; + for (0..p.view().cols[column].n -| 1) |index| { const seam = seamRowOf(p, column, index); if (@max(row, seam) - @min(row, seam) == slack) return .{ .col = col, .row = seam }; } @@ -259,11 +262,11 @@ test "a press near chrome takes it: the tag rows, a column's handle or a seam on defer p.deinit(); // Column 0's two panes share its rows evenly; column 1's lower one is // tall, its middle a body row. - const handle = p.col_x[0] + p.col_w[0] - 1; + const handle = p.view().col_x[0] + p.view().col_w[0] - 1; const seam = seamRowOf(p, 0, 0); - const mid = p.col_x[0] + p.col_w[0] / 2; - const top = p.rects[p.cols[0].panes[0]].y; - const low = p.rects[p.cols[1].panes[1]]; + const mid = p.view().col_x[0] + p.view().col_w[0] / 2; + const top = p.view().rects[p.view().cols[0].panes[0]].y; + const low = p.view().rects[p.view().cols[1].panes[1]]; const body = low.y + low.h / 2; try std.testing.expectEqual(ChromeTarget{ .col = 5, .row = 0 }, chromeTarget(p, 5, 0).?); try std.testing.expectEqual(ChromeTarget{ .col = handle, .row = body }, chromeTarget(p, handle, body).?); @@ -277,7 +280,7 @@ test "a press near chrome takes it: the tag rows, a column's handle or a seam on pub fn paneAt(p: *const Pardes, col: u16, row: u16) ?usize { for (p.panes, 0..) |slot, id| { if (slot == null) continue; - const r = p.rects[id]; + const r = p.view().rects[id]; if (col >= r.x and col < r.x + r.w and row >= r.y and row < r.y + r.h) return id; } return null; @@ -293,7 +296,7 @@ pub fn bodyHitForPane(p: *const Pardes, id: usize, supplied: Mouse.BodyHit, clam if (clamp) { // Onto the body the sweep is in: the place of its last hit there // (the drag's `body`), the hit's own while it is over it. - if (supplied.serial != pane.serial) mapped_hit.place = (if (p.drag == .select) p.drag.select.body else null) orelse return null; + if (supplied.serial != pane.serial) mapped_hit.place = (if (p.view().drag == .select) p.view().drag.select.body else null) orelse return null; mapped_hit.serial = pane.serial; if (mapped_hit.place.rows == 0) return null; const v = mapped_hit.place.viewport; @@ -329,7 +332,7 @@ fn programWheel(p: *Pardes, id: usize, m: Mouse, col: u16, row: u16) bool { if (m.shift) return false; const pane = p.panes[id] orelse return false; if (!pane.isTerminal() or !panes.terminal.ownsWheel(pane)) return false; - const r = p.rects[id]; + const r = p.view().rects[id]; const body_y = p.bodyTop(pane, r); const gcol = std.math.clamp(col -| (r.x + config.GUTTER), 0, pane.cols -| 1); const grow = std.math.clamp(row -| body_y, 0, pane.rows -| 1); @@ -359,7 +362,7 @@ pub const Grab = struct { /// the grid). fn programCell(p: *const Pardes, id: usize, col: u16, row: u16) ?struct { col: i32, row: i32 } { const pane = p.panes[id] orelse return null; - const r = p.rects[id]; + const r = p.view().rects[id]; const x0 = r.x + config.GUTTER; const y0 = p.bodyTop(pane, r); const h = @min(r.h -| pane.tag_rows, pane.rows); @@ -384,22 +387,24 @@ fn tracksMouse(pane: *const Pane) bool { /// The pointer over the body of a pane whose kind takes the mouse: the /// kind's, a press focusing the pane first. fn kindMouse(p: *Pardes, m: Mouse) bool { - if (p.drag != .none or p.header_drag or p.header_sweep != null) return false; + const v = p.view(); + if (v.drag != .none or v.header_drag or v.header_sweep != null) return false; for (p.panes, 0..) |slot, id| { const pane = slot orelse continue; const k = pane.addon orelse continue; if (!pardes.Kind.takesMouse(p, k) or pane.collapsed) continue; - const r = p.rects[id]; + const r = v.rects[id]; const top = p.bodyTop(pane, r) + pane.notices.span(); const x0 = r.x + config.GUTTER; if (m.col < x0 or m.col >= r.x + r.w or m.row < top or m.row >= r.y + r.h) continue; - if (m.kind == .press) p.active = id; + if (m.kind == .press) v.active = id; return pardes.Kind.mouse(p, id, m, m.col - x0, m.row - top); } return false; } fn programMouse(p: *Pardes, m: Mouse) bool { + const v = p.view(); const button: ?panes.terminal.MouseButton = switch (m.button) { .left => .left, .middle => .middle, @@ -408,22 +413,22 @@ fn programMouse(p: *Pardes, m: Mouse) bool { else => return false, }; const bit: u3 = if (button) |b| @as(u3, 1) << @intCast(@backingInt(b)) else 0; - const at: struct { col: u16, row: u16 } = .{ .col = @min(m.col, p.screen_w -| 1), .row = @min(m.row, p.screen_h -| 1) }; + const at: struct { col: u16, row: u16 } = .{ .col = @min(m.col, v.screen_w -| 1), .row = @min(m.row, v.screen_h -| 1) }; var mods: panes.terminal.MouseMods = .{ .shift = m.shift, .alt = m.alt, .ctrl = m.ctrl }; var buf: [64]u8 = undefined; - if (p.mouse_grab) |*grab| { + if (v.mouse_grab) |*grab| { if (grab.unshift) mods.shift = false; const pane = p.panes[grab.id] orelse { - p.mouse_grab = null; + v.mouse_grab = null; return false; }; if (pane.serial != grab.serial or !pane.isTerminal()) { - p.mouse_grab = null; + v.mouse_grab = null; return false; } // Off the grid the cell runs on past its edge, and the encoder // clamps it there. - const r = p.rects[grab.id]; + const r = v.rects[grab.id]; const col: i32 = @as(i32, at.col) - @as(i32, r.x + config.GUTTER); const row: i32 = @as(i32, at.row) - @as(i32, p.bodyTop(pane, r)); const action: panes.terminal.MouseAction = switch (m.kind) { @@ -435,10 +440,10 @@ fn programMouse(p: *Pardes, m: Mouse) bool { if (m.kind == .release) grab.held &= ~bit; const bytes = panes.terminal.mouseBytes(pane, &buf, action, button, mods, col, row, grab.held != 0); if (bytes.len > 0) p.emitWrite(grab.id, bytes); - if (grab.held == 0) p.mouse_grab = null; + if (grab.held == 0) v.mouse_grab = null; return true; } - if (p.drag != .none or p.header_drag or p.header_sweep != null) return false; + if (v.drag != .none or v.header_drag or v.header_sweep != null) return false; const shifted_to_program = m.button == .middle or m.button == .right; if (m.shift != shifted_to_program) return false; if (shifted_to_program) mods.shift = false; @@ -449,14 +454,14 @@ fn programMouse(p: *Pardes, m: Mouse) bool { const cell = programCell(p, id, mapped.col, mapped.row) orelse return false; switch (m.kind) { .press => { - if (id != p.active) if (p.panes[p.active]) |previous| { + if (id != v.active) if (p.panes[v.active]) |previous| { previous.focus = .body; previous.closePrompt(); }; - p.active = id; + v.active = id; pane.focus = .body; pane.closePrompt(); - p.mouse_grab = .{ .id = id, .serial = pane.serial, .held = bit, .unshift = shifted_to_program }; + v.mouse_grab = .{ .id = id, .serial = pane.serial, .held = bit, .unshift = shifted_to_program }; const bytes = panes.terminal.mouseBytes(pane, &buf, .press, button, mods, cell.col, cell.row, true); if (bytes.len > 0) p.emitWrite(id, bytes); return true; @@ -480,20 +485,22 @@ fn programMouse(p: *Pardes, m: Mouse) bool { /// meanwhile. Ctrl-click keeps its own meaning (a definition). Run after /// programMouse: a program that takes the click gets it as it was. fn emulateButton(p: *Pardes, m: *Mouse) void { + const v = p.view(); if (m.button != .left) return; - if (m.kind == .press) p.click_as = if (m.ctrl) null else if (m.super) .right else if (m.alt) .middle else null; - const as = p.click_as orelse return; + if (m.kind == .press) v.click_as = if (m.ctrl) null else if (m.super) .right else if (m.alt) .middle else null; + const as = v.click_as orelse return; m.button = as; m.alt = false; m.super = false; - if (m.kind == .release) p.click_as = null; + if (m.kind == .release) v.click_as = null; } pub fn handleMouse(p: *Pardes, event: Mouse) void { + const v = p.view(); var m = event; // A click goes somewhere else: the question it leaves unanswered is // taken back, and the pane stays. A wheel only looks around. - if (m.kind == .press) p.window_pick = null; + if (m.kind == .press) v.window_pick = null; if (m.kind == .press and switch (m.button) { .left, .middle, .right => true, else => false, @@ -508,37 +515,37 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void { // A grip let go past the window's edge, as a browser's tab dragged out // of its window: the pane or column goes to another window. Inside, the // grip's drag is the layout move below, as it always was. - if (m.kind == .release and m.outside and m.button == config.select_button) switch (p.drag) { + if (m.kind == .release and m.outside and m.button == config.select_button) switch (v.drag) { .move => |d| { - p.drag = .none; + v.drag = .none; return p.handover.begin(p, .pane, d.id); }, .column_move => |d| { - p.drag = .none; + v.drag = .none; const column = layout.columnBySerial(p, d.serial) orelse return; return p.handover.begin(p, .column, column); }, else => {}, }; - const raw_col = @min(m.col, p.screen_w -| 1); - const raw_row = @min(m.row, p.screen_h -| 1); - p.pointer_raw_col = raw_col; - p.pointer_raw_row = raw_row; - const previous_hit = p.pointer_body_hit; - p.pointer_body_hit = m.body_hit; - const previous_tag_hit = p.pointer_tag_hit; - p.pointer_tag_hit = if (m.tag_hit) |point| layout.reprojectTagHit(p, point) else null; - if (m.tag_hit != null and p.pointer_tag_hit == null and m.kind == .press) return; - if (m.tag_hit == null and (m.kind == .drag or m.kind == .release) and (p.drag == .select or p.header_drag or p.header_sweep != null)) { + const raw_col = @min(m.col, v.screen_w -| 1); + const raw_row = @min(m.row, v.screen_h -| 1); + v.pointer_raw_col = raw_col; + v.pointer_raw_row = raw_row; + const previous_hit = v.pointer_body_hit; + v.pointer_body_hit = m.body_hit; + const previous_tag_hit = v.pointer_tag_hit; + v.pointer_tag_hit = if (m.tag_hit) |point| layout.reprojectTagHit(p, point) else null; + if (m.tag_hit != null and v.pointer_tag_hit == null and m.kind == .press) return; + if (m.tag_hit == null and (m.kind == .drag or m.kind == .release) and (v.drag == .select or v.header_drag or v.header_sweep != null)) { if (previous_tag_hit) |previous| { var continued = previous; continued.pixel_x = (@as(f32, @floatFromInt(raw_col)) + 0.5) * @as(f32, @floatFromInt(previous.metrics.body_w)); continued.pixel_y = (@as(f32, @floatFromInt(raw_row)) + 0.5) * @as(f32, @floatFromInt(previous.metrics.body_h)); - p.pointer_tag_hit = continued; + v.pointer_tag_hit = continued; } } - if ((m.kind == .drag or m.kind == .release) and (p.drag == .select or p.header_drag or p.header_sweep != null)) { - if (previous_tag_hit) |previous| if (p.pointer_tag_hit) |*current| { + if ((m.kind == .drag or m.kind == .release) and (v.drag == .select or v.header_drag or v.header_sweep != null)) { + if (previous_tag_hit) |previous| if (v.pointer_tag_hit) |*current| { current.kind = previous.kind; current.id = previous.id; current.serial = previous.serial; @@ -548,43 +555,43 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void { } // A drag can leave the compact text viewport. Preserve its metrics so // the endpoint still clamps to that body's last visible logical row. - if (m.body_hit == null and (m.kind == .drag or m.kind == .release) and p.drag == .select) { + if (m.body_hit == null and (m.kind == .drag or m.kind == .release) and v.drag == .select) { if (previous_hit) |previous| { var continued = previous; continued.pixel_x = (@as(f32, @floatFromInt(raw_col)) + 0.5) * @as(f32, @floatFromInt(previous.metrics.body_w)); continued.pixel_y = (@as(f32, @floatFromInt(raw_row)) + 0.5) * @as(f32, @floatFromInt(previous.metrics.body_h)); - p.pointer_body_hit = continued; + v.pointer_body_hit = continued; } } - p.pointer_inside = true; + v.pointer_inside = true; if (kindMouse(p, m)) return; if (programMouse(p, m)) return; emulateButton(p, &m); if (m.button == .none and m.kind == .motion) { - p.raw_hover_intent = true; + v.raw_hover_intent = true; look.refreshLookHoverFromRaw(p); return; } - p.raw_hover_intent = false; + v.raw_hover_intent = false; const mapped: struct { col: u16, row: u16 } = .{ .col = raw_col, .row = raw_row }; const mcol = mapped.col; const mrow = mapped.row; - p.hover_col = mcol; - p.hover_row = mrow; + v.hover_col = mcol; + v.hover_row = mrow; const hovered = paneAt(p, mcol, mrow); // any press that is NOT the execute+select chord abandons a pending // chord argument if (m.kind == .press and - !(m.button == config.select_button and p.drag == .select and p.drag.select.button == config.exec_button)) + !(m.button == config.select_button and v.drag == .select and v.drag.select.button == config.exec_button)) { - if (p.chord_arg) |a| { + if (v.chord_arg) |a| { p.gpa.free(a); - p.chord_arg = null; + v.chord_arg = null; } } - if (p.header_sweep) |*sweep| { + if (v.header_sweep) |*sweep| { if (m.kind == .press and switch (m.button) { .left, .middle, .right => true, else => false, @@ -593,36 +600,36 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void { // sweep. The select button is inert: a header's command already // takes the held selection as its argument, which is what a 2-1 // chord would give it. - if (m.button != config.select_button) p.header_sweep = null; + if (m.button != config.select_button) v.header_sweep = null; return; } if (m.button == sweep.button and (m.kind == .drag or m.kind == .release)) { const column = sweep.column(p) catch { - p.header_sweep = null; + v.header_sweep = null; return; }; if (headerPoint(p, column, mcol, mrow, true)) |point| sweep.cur = point.at; if (m.kind == .release) { const done = sweep.*; - p.header_sweep = null; + v.header_sweep = null; headerSweepRun(p, done); } return; } } if (mrow >= p.topBarHeight() and mrow < p.topBarHeight() + layout.columnBarHeight(p) and m.kind == .press) { - for (0..p.ncol) |column| { - if (mcol < p.col_x[column] or mcol >= p.col_x[column] + @min(config.GUTTER, p.col_w[column])) continue; + for (0..p.view().ncol) |column| { + if (mcol < v.col_x[column] or mcol >= v.col_x[column] + @min(config.GUTTER, v.col_w[column])) continue; if (m.button == config.select_button) { - p.header_drag = false; - p.drag = .{ .column_move = .{ .serial = p.cols[column].serial, .cur_x = mcol, .grab = mcol - p.col_x[column] } }; + v.header_drag = false; + v.drag = .{ .column_move = .{ .serial = v.cols[column].serial, .cur_x = mcol, .grab = mcol - v.col_x[column] } }; } return; } } - if (p.header_drag and m.button == config.select_button and (m.kind == .drag or m.kind == .release)) { + if (v.header_drag and m.button == config.select_button and (m.kind == .drag or m.kind == .release)) { if (tagline.focusedHeader(p) == null) { - p.header_drag = false; + v.header_drag = false; return; } // Held to the focused header's rows and text; the anchor stays @@ -632,13 +639,13 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void { t.cur_row = point.line; t.cur_col = @intCast(point.at - modal.lineStartOffset(point.text, point.line)); t.vsel.active = t.vsel.row != t.cur_row or t.vsel.col != t.cur_col; - if (m.kind == .release) p.header_drag = false; + if (m.kind == .release) v.header_drag = false; return; } if (mrow < p.topBarHeight() + layout.columnBarHeight(p) and m.kind == .press and (m.button == config.select_button or m.button == config.exec_button or m.button == config.look_button)) { - if (m.button == config.select_button) if (p.panes[p.active]) |pane| { + if (m.button == config.select_button) if (p.panes[v.active]) |pane| { pane.focus = .body; pane.closePrompt(); }; @@ -646,11 +653,11 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void { var x: u16 = TAG_TEXT_INSET; if (mcol < x) return; if (mrow >= p.topBarHeight()) { - for (0..p.ncol) |c| if (mcol >= p.col_x[c] and mcol < p.col_x[c] + p.col_w[c]) { + for (0..p.view().ncol) |c| if (mcol >= v.col_x[c] and mcol < v.col_x[c] + v.col_w[c]) { column = c; - x = p.col_x[c] + TAG_TEXT_INSET; - if (layout.findPane(p, p.active)) |active_col| { - if (active_col.col != c and p.cols[c].n > 0) p.active = p.cols[c].panes[0]; + x = v.col_x[c] + TAG_TEXT_INSET; + if (layout.findPane(p, v.active)) |active_col| { + if (active_col.col != c and v.cols[c].n > 0) v.active = v.cols[c].panes[0]; } break; }; @@ -661,17 +668,17 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void { const t = point.t; const at = point.at - modal.lineStartOffset(point.text, point.line); // A clicked header starts in normal mode, as a clicked tag does. - if (!(p.header != null and p.headerColumn() == column)) tagline.enterHeader(p, column); + if (!(v.header != null and p.headerColumn() == column)) tagline.enterHeader(p, column); t.mode = .normal; t.cur_row = point.line; t.cur_col = @intCast(at); t.vsel = .{ .active = false, .row = point.line, .col = @intCast(at) }; - p.header_drag = true; + v.header_drag = true; } else { // Held, as a pane tag's sweep is: it runs when the button // comes up (headerSweepRun). - p.header_sweep = .{ - .serial = if (column) |c| p.cols[c].serial else null, + v.header_sweep = .{ + .serial = if (column) |c| v.cols[c].serial else null, .button = m.button, .anchor = point.at, .cur = point.at, @@ -689,7 +696,7 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void { if (m.kind != .press) return; // re-arms the drift guard below; vertical always scrolls, so // the answer is never in doubt here - _ = config.wheelTick(&p.wheel_guard, true); + _ = config.wheelTick(&v.wheel_guard, true); const id = hovered orelse return; const pane = p.panes[id].?; if (pane.hasPdf()) @@ -699,7 +706,7 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void { }, .wheel_left, .wheel_right => { if (m.kind != .press) return; - if (!config.wheelTick(&p.wheel_guard, false)) return; + if (!config.wheelTick(&v.wheel_guard, false)) return; const id = hovered orelse return; const pane = p.panes[id].?; if (programWheel(p, id, m, mcol, mrow)) { @@ -721,67 +728,67 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void { }, config.select_button => switch (m.kind) { .press => { - if (p.drag == .select and p.drag.select.button == config.exec_button) { - if (exec.heldSelection(p, p.drag.select.id)) |tx| { - if (p.chord_arg) |old| p.gpa.free(old); - p.chord_arg = p.gpa.dupe(u8, tx) catch null; + if (v.drag == .select and v.drag.select.button == config.exec_button) { + if (exec.heldSelection(p, v.drag.select.id)) |tx| { + if (v.chord_arg) |old| p.gpa.free(old); + v.chord_arg = p.gpa.dupe(u8, tx) catch null; } return; } // acme 3-1: a select tap during a LOOK drag cancels the // look; the rest of the gesture is inert - if (p.drag == .select and p.drag.select.button == config.look_button) { - if (p.panes[p.drag.select.id]) |t| { + if (v.drag == .select and v.drag.select.button == config.look_button) { + if (p.panes[v.drag.select.id]) |t| { t.sel[@backingInt(config.look_button)].state = .none; if (comptime pdf_enabled) - panes.Pdf.pointerCancel(t, p.drag.select.pdf); + panes.Pdf.pointerCancel(t, v.drag.select.pdf); } - p.drag = .none; + v.drag = .none; return; } if (hovered) |mid| { - const mr = p.rects[mid]; + const mr = v.rects[mid]; const mpane = p.panes[mid].?; const mtag = p.tagTop(mpane, mr); if (mcol < mr.x + config.GUTTER and mrow >= mtag and mrow < mtag + mpane.tag_rows) { - p.drag = .{ .move = .{ .id = mid, .cur_x = mcol, .cur_y = mrow } }; + v.drag = .{ .move = .{ .id = mid, .cur_x = mcol, .cur_y = mrow } }; return; } } - for (0..p.ncol -| 1) |c| { - if (mcol == p.col_x[c] + p.col_w[c] -| 1) { + for (0..p.view().ncol -| 1) |c| { + if (mcol == v.col_x[c] + v.col_w[c] -| 1) { const corner: @FieldType(@FieldType(Drag, "border_v"), "corner") = if (seamIdxAt(p, c, mrow)) |k| .{ .col = c, .idx = k } else if (seamIdxAt(p, c + 1, mrow)) |k| .{ .col = c + 1, .idx = k } else null; - p.drag = .{ .border_v = .{ .left_col = c, .cur_x = mcol, .corner = corner, .cur_y = mrow } }; + v.drag = .{ .border_v = .{ .left_col = c, .cur_x = mcol, .corner = corner, .cur_y = mrow } }; return; } } // Two panes are resized on the rule between them, never on a // row of text; with no rule, by the grip, as acme moves a // window by its button. - if (m.rule_above and mrow > 0) for (0..p.ncol) |cc| { - if (mcol < p.col_x[cc] or mcol >= p.col_x[cc] + p.col_w[cc]) continue; + if (m.rule_above and mrow > 0) for (0..p.view().ncol) |cc| { + if (mcol < v.col_x[cc] or mcol >= v.col_x[cc] + v.col_w[cc]) continue; const seam = mrow - 1; if (seamIdxAt(p, cc, seam)) |k| { - p.drag = .{ .border_h = .{ .col = cc, .top_idx = k, .cur_y = seam } }; + v.drag = .{ .border_h = .{ .col = cc, .top_idx = k, .cur_y = seam } }; return; } }; const id = hovered orelse return; - const r = p.rects[id]; + const r = v.rects[id]; const pane = p.panes[id] orelse return; - if (id != p.active) if (p.panes[p.active]) |previous| { + if (id != v.active) if (p.panes[v.active]) |previous| { previous.focus = .body; previous.closePrompt(); }; const tag_y = p.tagTop(pane, r); const body_y = p.bodyTop(pane, r); if (mcol < r.x + config.GUTTER) { - p.active = id; + v.active = id; // A tick of the pane's places: that place, selected and in view. // The rail is chrome, and only the tick's cell does this. const rail_h = r.h -| pane.tag_rows; @@ -794,10 +801,10 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void { } else { const on_tag = mrow >= tag_y and mrow < tag_y + pane.tag_rows; if (on_tag and mcol < r.x + TAG_TEXT_INSET) return; - p.active = id; + v.active = id; layout.noteTyped(p); // acme's button 1 sets activecol (acme.c:659) pane.closePrompt(); - const pointed = edit.pointerTextSelection(p, id, mcol, mrow, m.body_hit, p.pointer_tag_hit) orelse return; + const pointed = edit.pointerTextSelection(p, id, mcol, mrow, m.body_hit, v.pointer_tag_hit) orelse return; pane.clearPointerSelection(sel_slot); pane.sel[sel_slot] = pointed.sel; // A clicked tag starts in normal mode, its cursor where it @@ -815,7 +822,7 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void { pane.tag.cur_row = @intCast(at.row); pane.tag.cur_col = @intCast(at.col); } - p.drag = .{ .select = .{ + v.drag = .{ .select = .{ .id = id, .button = config.select_button, .ctrl = m.ctrl, @@ -831,9 +838,9 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void { } }; } }, - .drag => dragUpdate(p, mcol, mrow, p.pointer_body_hit), + .drag => dragUpdate(p, mcol, mrow, v.pointer_body_hit), .release => { - if ((p.pointer_body_hit != null or p.pointer_tag_hit != null or p.drag == .column_move) and p.drag.button() == m.button) dragUpdate(p, mcol, mrow, p.pointer_body_hit); + if ((v.pointer_body_hit != null or v.pointer_tag_hit != null or v.drag == .column_move) and v.drag.button() == m.button) dragUpdate(p, mcol, mrow, v.pointer_body_hit); dragRelease(p, config.select_button); }, .motion => {}, @@ -842,23 +849,23 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void { .press => { // acme 1-2 / 1-3: the execute (Cut) or look (Paste) button // tapped while the select button holds a selection drag - if (p.drag == .select and p.drag.select.button == config.select_button) { + if (v.drag == .select and v.drag.select.button == config.select_button) { chordCutPaste(p, m.button == config.exec_button); return; } // acme 2-3 / 3-2: tapping the OTHER of execute/look during // an execute or look drag cancels it (textselect23's mask) - if (p.drag == .select) { - if (p.panes[p.drag.select.id]) |t| { - t.sel[@backingInt(p.drag.select.button)].state = .none; + if (v.drag == .select) { + if (p.panes[v.drag.select.id]) |t| { + t.sel[@backingInt(v.drag.select.button)].state = .none; if (comptime pdf_enabled) - panes.Pdf.pointerCancel(t, p.drag.select.pdf); + panes.Pdf.pointerCancel(t, v.drag.select.pdf); } - p.drag = .none; + v.drag = .none; return; } const id = hovered orelse return; - const r = p.rects[id]; + const r = v.rects[id]; const pane = p.panes[id] orelse return; // the tag row and the body's first, exactly as the select // arm above derives them @@ -867,13 +874,13 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void { const on_tag = mrow >= tag_y and mrow < tag_y + pane.tag_rows; if (mcol < r.x + config.GUTTER and !on_tag) { const local = @as(i32, mrow) - @as(i32, body_y); - if (m.button == config.look_button) p.active = id; + if (m.button == config.look_button) v.active = id; pane.scrollBy(if (m.button == config.look_button) local else -local); - } else if (edit.pointerTextSelection(p, id, mcol, mrow, m.body_hit, p.pointer_tag_hit)) |pointed| { - if (m.button == config.look_button) p.active = id; + } else if (edit.pointerTextSelection(p, id, mcol, mrow, m.body_hit, v.pointer_tag_hit)) |pointed| { + if (m.button == config.look_button) v.active = id; pane.clearPointerSelection(@backingInt(m.button)); pane.sel[@backingInt(m.button)] = pointed.sel; - p.drag = .{ + v.drag = .{ .select = .{ .id = id, .button = m.button, @@ -892,9 +899,9 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void { }; } }, - .drag => dragUpdate(p, mcol, mrow, p.pointer_body_hit), + .drag => dragUpdate(p, mcol, mrow, v.pointer_body_hit), .release => { - if ((p.pointer_body_hit != null or p.pointer_tag_hit != null or p.drag == .column_move) and p.drag.button() == m.button) dragUpdate(p, mcol, mrow, p.pointer_body_hit); + if ((v.pointer_body_hit != null or v.pointer_tag_hit != null or v.drag == .column_move) and v.drag.button() == m.button) dragUpdate(p, mcol, mrow, v.pointer_body_hit); dragRelease(p, m.button); }, .motion => {}, @@ -905,22 +912,23 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void { /// Index of the pane pair in column `c` whose seam (see seamRowOf) is screen /// row `mrow`. Out-of-range columns simply have no seam. fn seamIdxAt(p: *const Pardes, c: usize, mrow: u16) ?usize { - if (c >= p.ncol) return null; - for (0..p.cols[c].n -| 1) |k| if (mrow == seamRowOf(p, c, k)) return k; + if (c >= p.view().ncol) return null; + for (0..p.view().cols[c].n -| 1) |k| if (mrow == seamRowOf(p, c, k)) return k; return null; } pub fn dragUpdate(p: *Pardes, mcol: u16, mrow: u16, body_hit: ?Mouse.BodyHit) void { - switch (p.drag) { + const v = p.view(); + switch (v.drag) { .border_v => |*d| { const c = d.left_col; - d.cur_x = if (c + 1 < p.ncol) - clampBorderCol(p.col_x[c], p.col_w[c], p.col_w[c + 1], mcol) + d.cur_x = if (c + 1 < v.ncol) + clampBorderCol(v.col_x[c], v.col_w[c], v.col_w[c + 1], mcol) else mcol; - if (d.corner) |k| if (k.idx + 1 < p.cols[k.col].n) { - const a = p.rects[p.cols[k.col].panes[k.idx]]; - const b = p.rects[p.cols[k.col].panes[k.idx + 1]]; + if (d.corner) |k| if (k.idx + 1 < v.cols[k.col].n) { + const a = v.rects[v.cols[k.col].panes[k.idx]]; + const b = v.rects[v.cols[k.col].panes[k.idx + 1]]; d.cur_y = clampBorderRow(a.y, a.h, b.h, mrow); } else { d.cur_y = mrow; @@ -929,9 +937,9 @@ pub fn dragUpdate(p: *Pardes, mcol: u16, mrow: u16, body_hit: ?Mouse.BodyHit) vo .border_h => |*d| { const cc = d.col; const k = d.top_idx; - if (k + 1 < p.cols[cc].n) { - const a = p.rects[p.cols[cc].panes[k]]; - const b = p.rects[p.cols[cc].panes[k + 1]]; + if (k + 1 < v.cols[cc].n) { + const a = v.rects[v.cols[cc].panes[k]]; + const b = v.rects[v.cols[cc].panes[k + 1]]; // Held by the rule over the lower pane: the seam is the row above. d.cur_y = clampBorderRow(a.y, a.h, b.h, mrow -| 1); } else d.cur_y = mrow; @@ -943,7 +951,7 @@ pub fn dragUpdate(p: *Pardes, mcol: u16, mrow: u16, body_hit: ?Mouse.BodyHit) vo }, .select => |*s| { if (p.panes[s.id]) |pane| { - const r = p.rects[s.id]; + const r = v.rects[s.id]; const b = @backingInt(s.button); const tag_rows: i32 = pane.tag_rows; panes.File.geometry(pane); @@ -958,7 +966,7 @@ pub fn dragUpdate(p: *Pardes, mcol: u16, mrow: u16, body_hit: ?Mouse.BodyHit) vo // nearest the pointer. const tag_y = p.tagTop(pane, r); const tag_line: u16 = @intCast(std.math.clamp(@as(i32, mrow) - @as(i32, tag_y), 0, tag_rows - 1)); - if (pane.sel[b].r0 < tag_rows) if (Layer.columnAt(p, .pane, s.id, p.pointer_tag_hit, true, tag_line)) |value| { + if (pane.sel[b].r0 < tag_rows) if (Layer.columnAt(p, .pane, s.id, v.pointer_tag_hit, true, tag_line)) |value| { pane.sel[b].c1 = @as(i32, value) + pane.tag_scroll; pane.sel[b].r1 = tag_line; return; @@ -978,7 +986,7 @@ pub fn dragUpdate(p: *Pardes, mcol: u16, mrow: u16, body_hit: ?Mouse.BodyHit) vo else if (mrow >= body_y + body_h or // The pointer cannot leave the screen: at a bottom pane, // its last row is the edge. - (body_y + body_h >= p.screen_h and mrow + 1 >= body_y + body_h)) + (body_y + body_h >= v.screen_h and mrow + 1 >= body_y + body_h)) 1 else 0; @@ -1105,8 +1113,8 @@ pub fn dispatchPointerBuiltin( text: ?[]const u8, gesture: ?struct { on_tag: bool, operand: exec.PointerOperand }, ) void { - const arg = p.chord_arg; - p.chord_arg = null; + const arg = p.view().chord_arg; + p.view().chord_arg = null; defer if (arg) |a| p.gpa.free(a); // A click that takes no text does nothing, and tells an event reader // nothing, as acme's look3 and execute return on an empty expansion. @@ -1158,14 +1166,15 @@ fn mirrorTtySelection(p: *Pardes, pane: *Pane) void { /// second selects what edit.doubleClickRange says, from the caret the click /// left. A plain click still puts the caret on its cell. fn doubleClick(p: *Pardes, id: usize, t: *panes.Text, on_tag: bool, row: i32, col: i32) void { + const v = p.view(); // The host's clock, which every host keeps and a test's virtual one // replaces. const now: i64 = @intCast(p.clock.now_ns / std.time.ns_per_ms); - const prev = p.last_click; - p.last_click = .{ .id = id, .on_tag = on_tag, .row = row, .col = col, .ms = now }; + const prev = v.last_click; + v.last_click = .{ .id = id, .on_tag = on_tag, .row = row, .col = col, .ms = now }; const c = prev orelse return; if (c.id != id or c.on_tag != on_tag or c.row != row or c.col != col or now - c.ms > 500) return; - p.last_click = null; + v.last_click = null; const text = edit.flatSurface(p, t) catch return; const q = modal.offsetAt(text, .{ .row = @intCast(@max(0, t.cur_row)), .col = @intCast(@max(0, t.cur_col)) }); const r = edit.doubleClickRange(text, q); @@ -1182,8 +1191,8 @@ fn doubleClick(p: *Pardes, id: usize, t: *panes.Text, on_tag: bool, row: i32, co /// scrolls a line toward it, the sweep's end stays under the pointer and /// its start stays on its text (Drag.select.anchor). pub fn edgeScroll(p: *Pardes) void { - if (p.drag != .select) return; - const s = &p.drag.select; + if (p.view().drag != .select) return; + const s = &p.view().drag.select; if (s.edge == 0) return; const pane = p.panes[s.id] orelse return; const sl = &pane.sel[sel_slot]; @@ -1207,19 +1216,20 @@ fn sweepPoint(p: *Pardes, pane: *panes.Pane, r: i32, c: i32) ?modal.Cursor { } fn dragRelease(p: *Pardes, button: Mouse.Button) void { + const v = p.view(); // A different button's release belongs to a chord or another host // stream; only the button which began this gesture may end it. - if (p.drag.button() != button) return; - defer p.drag = .none; - defer p.chord_hold = false; - switch (p.drag) { + if (v.drag.button() != button) return; + defer v.drag = .none; + defer v.chord_hold = false; + switch (v.drag) { .border_v => |d| { const c = d.left_col; - const old_seam = p.col_x[c] + p.col_w[c] -| 1; + const old_seam = v.col_x[c] + v.col_w[c] -| 1; // the handle is the left pane's LAST column (inclusive), so // the new width includes it — a no-drag click changes nothing - if (c + 1 < p.ncol and d.cur_x != old_seam) - layout.setColumnPairWidth(p, c, (d.cur_x + 1) -| p.col_x[c]); + if (c + 1 < v.ncol and d.cur_x != old_seam) + layout.setColumnPairWidth(p, c, (d.cur_x + 1) -| v.col_x[c]); if (d.corner) |k| { if (d.cur_y != seamRowOf(p, k.col, k.idx)) layout.applyRowSplit(p, k.col, k.idx, d.cur_y); @@ -1233,7 +1243,7 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void { layout.reorderColumn(p, column, target); p.setActiveColumn(target); // a grip drag sets activecol (acme.c:640) }, - .edge => |x| layout.setColumnPairWidth(p, column - 1, x - p.col_x[column - 1]), + .edge => |x| layout.setColumnPairWidth(p, column - 1, x - v.col_x[column - 1]), }, .move => |d| { layout.movePane(p, d.id, d.cur_x, d.cur_y); @@ -1315,7 +1325,7 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void { pane.body.sticky_col = -1; // A ctrl-click is a definition jump, not half a double-click. if (!dragged and !s.ctrl) doubleClick(p, s.id, &pane.body, false, sl.r1, sl.c1); - if (s.ctrl) p.last_click = null; + if (s.ctrl) v.last_click = null; // A sweep that scrolled has its start off the screen: it // is kept as the text's own selection, start to end. if (dragged) if (s.anchor) |a| { @@ -1390,7 +1400,7 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void { } fn chordCutPaste(p: *Pardes, cut: bool) void { - const s = &p.drag.select; + const s = &p.view().drag.select; const pane = p.panes[s.id] orelse return; if (comptime pdf_enabled) if (pane.pdf) |pv| { if (!s.chorded) { @@ -1460,7 +1470,7 @@ fn chordCutPaste(p: *Pardes, cut: bool) void { // marks the file once per B1 hold (text.c:881 textselect, `state` // and its one filemark): B1-B2 then B1-B3 is a copy. edit.pushUndo(p, &pane.body); - p.chord_hold = true; + p.view().chord_hold = true; const sl = pane.sel[sel_slot]; pane.sel[sel_slot].state = .none; const pfx: i32 = if (pane.file != null) panes.File.gutterWidth(pane) else 0; @@ -1521,7 +1531,7 @@ test "plain left click clears explicit modal selection" { var frame = std.heap.ArenaAllocator.init(gpa); defer frame.deinit(); _ = try p.render(frame.allocator()); - const rect = p.rects[0]; + const rect = p.view().rects[0]; const click_x = rect.x + config.GUTTER + config.PREFIX_W + 3; const body_y = rect.y + BOX_H; p.update(.{ .mouse = .{ .button = config.select_button, .kind = .press, .col = click_x, .row = body_y } }); @@ -1536,14 +1546,14 @@ test "a selection drag and its release leave the selection done" { const p = try Pardes.init(std.testing.allocator, .{ .cols = 50, .rows = 10, .tty_only = true }); defer p.deinit(); const pane = try p.setTestFile("alpha beta\n"); - const rect = p.rects[0]; + const rect = p.view().rects[0]; const x = rect.x + config.GUTTER + config.PREFIX_W + 1; const y = rect.y + BOX_H; p.update(.{ .mouse = .{ .button = config.select_button, .kind = .press, .col = x, .row = y } }); p.update(.{ .mouse = .{ .button = config.select_button, .kind = .drag, .col = x + 2, .row = y } }); p.update(.{ .mouse = .{ .button = config.select_button, .kind = .release, .col = x + 2, .row = y } }); - try std.testing.expect(p.drag == .none); + try std.testing.expect(p.view().drag == .none); try std.testing.expectEqual(.done, pane.sel[sel_slot].state); } @@ -1586,19 +1596,19 @@ test "a corner drag's two axes clamp independently" { test "a v-handle press at the RIGHT column's seam drags both boundaries" { const p = try cornerFixture(std.testing.allocator); defer p.deinit(); - try std.testing.expectEqual(@as(usize, 2), p.cols[1].n); + try std.testing.expectEqual(@as(usize, 2), p.view().cols[1].n); - const handle = p.col_x[0] + p.col_w[0] - 1; + const handle = p.view().col_x[0] + p.view().col_w[0] - 1; const right_seam = nudgeRightSeam(p, 3); try std.testing.expect(right_seam != seamRowOf(p, 0, 0)); - const w0 = p.cols[0].weight; - const v_left = p.panes[p.cols[0].panes[0]].?.vweight; - const v_right = p.panes[p.cols[1].panes[0]].?.vweight; + const w0 = p.view().cols[0].weight; + const v_left = p.panes[p.view().cols[0].panes[0]].?.vweight; + const v_right = p.panes[p.view().cols[1].panes[0]].?.vweight; p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = handle, .row = right_seam } }); - try std.testing.expect(p.drag == .border_v); - const corner = p.drag.border_v.corner orelse return error.NoCorner; + try std.testing.expect(p.view().drag == .border_v); + const corner = p.view().drag.border_v.corner orelse return error.NoCorner; try std.testing.expectEqual(@as(usize, 1), corner.col); try std.testing.expectEqual(@as(usize, 0), corner.idx); @@ -1608,9 +1618,9 @@ test "a v-handle press at the RIGHT column's seam drags both boundaries" { // both halves committed: the column pair widened, and the RIGHT column's // pane pair reweighted — while the left column's panes stayed put - try std.testing.expect(p.cols[0].weight > w0); - try std.testing.expect(p.panes[p.cols[1].panes[0]].?.vweight != v_right); - try std.testing.expectEqual(v_left, p.panes[p.cols[0].panes[0]].?.vweight); + try std.testing.expect(p.view().cols[0].weight > w0); + try std.testing.expect(p.panes[p.view().cols[1].panes[0]].?.vweight != v_right); + try std.testing.expectEqual(v_left, p.panes[p.view().cols[0].panes[0]].?.vweight); } test "a tie row still moves the LEFT column's pane pair only" { @@ -1623,19 +1633,19 @@ test "a tie row still moves the LEFT column's pane pair only" { _ = nudgeRightSeam(p, @as(i32, left_seam) - @as(i32, seamRowOf(p, 1, 0))); try std.testing.expectEqual(left_seam, seamRowOf(p, 1, 0)); - const handle = p.col_x[0] + p.col_w[0] - 1; - const v_left = p.panes[p.cols[0].panes[0]].?.vweight; - const v_right = p.panes[p.cols[1].panes[0]].?.vweight; + const handle = p.view().col_x[0] + p.view().col_w[0] - 1; + const v_left = p.panes[p.view().cols[0].panes[0]].?.vweight; + const v_right = p.panes[p.view().cols[1].panes[0]].?.vweight; p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = handle, .row = left_seam } }); - const corner = p.drag.border_v.corner orelse return error.NoCorner; + const corner = p.view().drag.border_v.corner orelse return error.NoCorner; try std.testing.expectEqual(@as(usize, 0), corner.col); p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = handle, .row = left_seam - 4 } }); p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = handle, .row = left_seam - 4 } }); p.sync(); - try std.testing.expect(p.panes[p.cols[0].panes[0]].?.vweight != v_left); - try std.testing.expectEqual(v_right, p.panes[p.cols[1].panes[0]].?.vweight); + try std.testing.expect(p.panes[p.view().cols[0].panes[0]].?.vweight != v_left); + try std.testing.expectEqual(v_right, p.panes[p.view().cols[1].panes[0]].?.vweight); } test "a v-handle press at nobody's seam is still a plain edge drag" { @@ -1644,44 +1654,44 @@ test "a v-handle press at nobody's seam is still a plain edge drag" { const right_seam = nudgeRightSeam(p, 3); const left_seam = seamRowOf(p, 0, 0); - const handle = p.col_x[0] + p.col_w[0] - 1; + const handle = p.view().col_x[0] + p.view().col_w[0] - 1; var row: u16 = TOPBAR_H + 1; while (row == left_seam or row == right_seam) row += 1; - const w0 = p.cols[0].weight; - const v_left = p.panes[p.cols[0].panes[0]].?.vweight; - const v_right = p.panes[p.cols[1].panes[0]].?.vweight; + const w0 = p.view().cols[0].weight; + const v_left = p.panes[p.view().cols[0].panes[0]].?.vweight; + const v_right = p.panes[p.view().cols[1].panes[0]].?.vweight; p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = handle, .row = row } }); - try std.testing.expect(p.drag == .border_v); - try std.testing.expect(p.drag.border_v.corner == null); + try std.testing.expect(p.view().drag == .border_v); + try std.testing.expect(p.view().drag.border_v.corner == null); p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = handle + 8, .row = row + 5 } }); p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = handle + 8, .row = row + 5 } }); p.sync(); // exactly ONE boundary moved - try std.testing.expect(p.cols[0].weight > w0); - try std.testing.expectEqual(v_left, p.panes[p.cols[0].panes[0]].?.vweight); - try std.testing.expectEqual(v_right, p.panes[p.cols[1].panes[0]].?.vweight); + try std.testing.expect(p.view().cols[0].weight > w0); + try std.testing.expectEqual(v_left, p.panes[p.view().cols[0].panes[0]].?.vweight); + try std.testing.expectEqual(v_right, p.panes[p.view().cols[1].panes[0]].?.vweight); } test "a RIGHT-column corner's two axes clamp independently" { const p = try cornerFixture(std.testing.allocator); defer p.deinit(); const right_seam = nudgeRightSeam(p, 3); - const handle = p.col_x[0] + p.col_w[0] - 1; + const handle = p.view().col_x[0] + p.view().col_w[0] - 1; p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = handle, .row = right_seam } }); - try std.testing.expectEqual(@as(usize, 1), (p.drag.border_v.corner orelse return error.NoCorner).col); + try std.testing.expectEqual(@as(usize, 1), (p.view().drag.border_v.corner orelse return error.NoCorner).col); // off the right edge at mid-height: x parks at its MINW wall, y is the mouse p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = 999, .row = right_seam } }); - try std.testing.expectEqual(@as(u16, 100 - config.MINW), p.drag.border_v.cur_x); - try std.testing.expectEqual(right_seam, p.drag.border_v.cur_y); + try std.testing.expectEqual(@as(u16, 100 - config.MINW), p.view().drag.border_v.cur_x); + try std.testing.expectEqual(right_seam, p.view().drag.border_v.cur_y); // and the mirror: below the bottom at mid-width. y parks, x tracks again p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = handle, .row = 999 } }); - try std.testing.expectEqual(handle, p.drag.border_v.cur_x); - const a = p.rects[p.cols[1].panes[0]]; - const b = p.rects[p.cols[1].panes[1]]; - try std.testing.expectEqual(clampBorderRow(a.y, a.h, b.h, 999), p.drag.border_v.cur_y); + try std.testing.expectEqual(handle, p.view().drag.border_v.cur_x); + const a = p.view().rects[p.view().cols[1].panes[0]]; + const b = p.view().rects[p.view().cols[1].panes[1]]; + try std.testing.expectEqual(clampBorderRow(a.y, a.h, b.h, 999), p.view().drag.border_v.cur_y); p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = handle, .row = 999 } }); } @@ -1690,20 +1700,20 @@ test "mouse thumb buttons navigate once and clear selection gestures" { defer p.deinit(); const pane = try p.setTestFile("alpha beta\ngamma delta\nepsilon zeta\n"); pane.body.setRange(pane.file.?.content, 0, .{ .anchor = 1, .head = 5 }, true); - p.jumps.n = 3; - p.jumps.cur = 2; - for (0..3) |i| p.jumps.list[i] = .{ .pane = 0, .serial = pane.serial, .line = @intCast(i + 1), .col = 1 }; - p.drag = .{ .select = .{ .id = 0, .button = config.select_button } }; + p.view().jumps.n = 3; + p.view().jumps.cur = 2; + for (0..3) |i| p.view().jumps.list[i] = .{ .pane = 0, .serial = pane.serial, .line = @intCast(i + 1), .col = 1 }; + p.view().drag = .{ .select = .{ .id = 0, .button = config.select_button } }; p.update(.{ .mouse = .{ .button = .back, .kind = .press, .col = 0, .row = 0 } }); - try std.testing.expectEqual(@as(usize, 1), p.jumps.cur); + try std.testing.expectEqual(@as(usize, 1), p.view().jumps.cur); for ([_]Mouse.Kind{ .drag, .release, .motion }) |kind| p.update(.{ .mouse = .{ .button = .back, .kind = kind, .col = 0, .row = 0 } }); - try std.testing.expectEqual(@as(usize, 1), p.jumps.cur); + try std.testing.expectEqual(@as(usize, 1), p.view().jumps.cur); p.update(.{ .mouse = .{ .button = .forward, .kind = .press, .col = 0, .row = 0 } }); p.update(.{ .mouse = .{ .button = .forward, .kind = .release, .col = 0, .row = 0 } }); - try std.testing.expectEqual(@as(usize, 2), p.jumps.cur); + try std.testing.expectEqual(@as(usize, 2), p.view().jumps.cur); try std.testing.expect(!pane.body.vsel.active); - try std.testing.expectEqual(.none, p.drag); + try std.testing.expectEqual(.none, p.view().drag); } test "a chorded exec an event reader holds is told with its argument, and written back runs with it" { @@ -1715,7 +1725,7 @@ test "a chorded exec an event reader holds is told with its argument, and writte const h = th.call(p, .{ .tag = 1, .op = .open, .node = event, .omode = 2 }).reply.handle; // The argument: a selection held in the pane (its second line). ctlfs.pane.setDot(p.panes[0].?, .{ .q0 = 9, .q1 = 17 }); - p.chord_arg = try p.gpa.dupe(u8, "arg-text"); + p.view().chord_arg = try p.gpa.dupe(u8, "arg-text"); dispatchPointerBuiltin(p, 0, config.exec_cmd, "Msg", .{ .on_tag = false, .operand = .{ .row = 0, .col = 1, .text = "Msg" } }); var records: [3][]const u8 = undefined; var got: [3][64]u8 = undefined; @@ -1763,7 +1773,7 @@ test "a wheel over a program that owns it is the program's, in the form it asked var out: [4096]u8 = undefined; _ = pardes.test_api.ptyBytes(p, 0, &out); const pane = p.panes[0].?; - const r = p.rects[0]; + const r = p.view().rects[0]; // Grid cell 6,4 (1-based), as a program counts. const col = r.x + config.GUTTER + 5; const row = p.bodyTop(pane, r) + 3; @@ -1824,28 +1834,28 @@ test "Alt-click is B2 and Super-click B3, kept from the press through the releas defer p.deinit(); const file = try p.setTestFile("Newcol here\n"); p.presented(); - const r = p.rects[0]; + const r = p.view().rects[0]; const col = r.x + config.GUTTER + panes.File.gutterWidth(file) + 1; const row = p.bodyTop(file, r); // A Super-press sweeps with B3's selection, not B1's. p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = col, .row = row, .super = true } }); - try std.testing.expect(p.drag == .select and file.sel[2].state != .none and file.sel[0].state == .none); + try std.testing.expect(p.view().drag == .select and file.sel[2].state != .none and file.sel[0].state == .none); p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = col, .row = row } }); - try std.testing.expect(p.drag == .none); - try std.testing.expectEqual(@as(?Mouse.Button, null), p.click_as); + try std.testing.expect(p.view().drag == .none); + try std.testing.expectEqual(@as(?Mouse.Button, null), p.view().click_as); // Ctrl with Alt is Ctrl's: a B1 click (a definition), never B2. - const cols = p.ncol; + const cols = p.view().ncol; p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = col, .row = row, .ctrl = true, .alt = true } }); - try std.testing.expectEqual(@as(?Mouse.Button, null), p.click_as); + try std.testing.expectEqual(@as(?Mouse.Button, null), p.view().click_as); p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = col, .row = row, .ctrl = true } }); - try std.testing.expectEqual(cols, p.ncol); + try std.testing.expectEqual(cols, p.view().ncol); // Alt-click on Newcol runs it, as B2 does, though Alt is let go // before the button. p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = col, .row = row, .alt = true } }); - try std.testing.expectEqual(@as(?Mouse.Button, .middle), p.click_as); + try std.testing.expectEqual(@as(?Mouse.Button, .middle), p.view().click_as); p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = col, .row = row } }); - try std.testing.expectEqual(cols + 1, p.ncol); - try std.testing.expectEqual(@as(?Mouse.Button, null), p.click_as); + try std.testing.expectEqual(cols + 1, p.view().ncol); + try std.testing.expectEqual(@as(?Mouse.Button, null), p.view().click_as); } test "a program tracking the mouse gets its clicks, drags and moves over its grid as xterm reports them; Shift and chrome stay pardes's" { @@ -1859,7 +1869,7 @@ test "a program tracking the mouse gets its clicks, drags and moves over its gri _ = pardes.test_api.ptyBytes(p, 0, &out); const pane = p.panes[0].?; try std.testing.expectEqual(.tty, pane.body.mode); - const r = p.rects[0]; + const r = p.view().rects[0]; const col = r.x + config.GUTTER + 5; const row = p.bodyTop(pane, r) + 3; const Ev = struct { button: Mouse.Button, kind: Mouse.Kind, dx: i32 = 0, dy: i32 = 0, shift: bool = false, alt: bool = false, ctrl: bool = false, super: bool = false }; @@ -1882,7 +1892,7 @@ test "a program tracking the mouse gets its clicks, drags and moves over its gri p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?1049h\x1b[?1h\x1b[?1006;1000h" } }); _ = pardes.test_api.ptyBytes(p, 0, &out); try std.testing.expectEqualStrings("\x1b[<0;6;4M", try send(p, &out, col, row, .{ .button = .left, .kind = .press })); - try std.testing.expect(p.drag == .none); + try std.testing.expect(p.view().drag == .none); // 1000 has no drags; the release is reported where it lands. try std.testing.expectEqualStrings("", try send(p, &out, col, row, .{ .button = .left, .kind = .drag, .dx = 1 })); try std.testing.expectEqualStrings("\x1b[<0;7;4m", try send(p, &out, col, row, .{ .button = .left, .kind = .release, .dx = 1 })); @@ -1892,12 +1902,12 @@ test "a program tracking the mouse gets its clicks, drags and moves over its gri try std.testing.expectEqualStrings("\x1b[<0;6;4m", try send(p, &out, col, row, .{ .button = .left, .kind = .release })); try std.testing.expectEqualStrings("\x1b[<0;6;4M", try send(p, &out, col, row, .{ .button = .left, .kind = .press, .super = true })); try std.testing.expectEqualStrings("\x1b[<0;6;4m", try send(p, &out, col, row, .{ .button = .left, .kind = .release, .super = true })); - try std.testing.expect(p.drag == .none); + try std.testing.expect(p.view().drag == .none); // B2 and B3 are pardes's execute and look, as in any pane. try std.testing.expectEqualStrings("", try send(p, &out, col, row, .{ .button = .right, .kind = .press })); - try std.testing.expect(p.drag == .select); + try std.testing.expect(p.view().drag == .select); try std.testing.expectEqualStrings("", try send(p, &out, col, row, .{ .button = .right, .kind = .release })); - try std.testing.expect(p.drag == .none); + try std.testing.expect(p.view().drag == .none); // Shift-B3 is the program's, the Shift that chose it left out: meta // and ctrl, 2 + 8 + 16. try std.testing.expectEqualStrings("\x1b[<26;6;4M", try send(p, &out, col, row, .{ .button = .right, .kind = .press, .shift = true, .alt = true, .ctrl = true })); @@ -1908,10 +1918,10 @@ test "a program tracking the mouse gets its clicks, drags and moves over its gri try std.testing.expectEqualStrings("", try send(p, &out, col, row, .{ .button = .none, .kind = .motion })); // Shift: pardes's own sweep, the program hears nothing of it. try std.testing.expectEqualStrings("", try send(p, &out, col, row, .{ .button = .left, .kind = .press, .shift = true })); - try std.testing.expect(p.drag == .select); + try std.testing.expect(p.view().drag == .select); try std.testing.expectEqualStrings("", try send(p, &out, col, row, .{ .button = .left, .kind = .drag, .dx = 2 })); try std.testing.expectEqualStrings("", try send(p, &out, col, row, .{ .button = .left, .kind = .release, .dx = 2 })); - try std.testing.expect(p.drag == .none); + try std.testing.expect(p.view().drag == .none); // Chrome is never the program's: the tag, and the gutter. const tag_row = p.tagTop(pane, r); try std.testing.expectEqualStrings("", try send(p, &out, col, tag_row, .{ .button = .right, .kind = .press })); @@ -1931,7 +1941,7 @@ test "a program tracking the mouse gets its clicks, drags and moves over its gri // Up over the tag: row 1, the grid's first. try std.testing.expectEqualStrings("\x1b[<32;7;1M", try send(p, &out, col + 1, tag_row, .{ .button = .left, .kind = .drag })); try std.testing.expectEqualStrings("\x1b[<0;7;1m", try send(p, &out, col + 1, tag_row, .{ .button = .left, .kind = .release })); - try std.testing.expect(p.mouse_grab == null); + try std.testing.expect(p.view().mouse_grab == null); // Over the tag a bare move is pardes's. try std.testing.expectEqualStrings("", try send(p, &out, col, tag_row, .{ .button = .none, .kind = .motion })); // B2 held for pardes: its sweep's moves are not the program's; held |
