diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-04 23:33:59 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-05 01:00:59 -0300 |
| commit | ef78fbd9cefc17da4f4be82545a055ea4c6b591c (patch) | |
| tree | 9db377baaf08528e4594dddbcb70147705069336 /src/mouse.zig | |
| parent | 463f319643848b9361eef140497b5a166e3945e3 (diff) | |
| download | pardes-ef78fbd9cefc17da4f4be82545a055ea4c6b591c.tar.gz pardes-ef78fbd9cefc17da4f4be82545a055ea4c6b591c.zip | |
mouse: a header drag takes its point from headerPoint, as a press does, where it worked the same offset out again line for line; reportGesture, a call of reportRange, is that call at its one caller; Pardes.reprojectBodyHit, which ignored its receiver, is Layer.bodyAgain where it was called; wordAtCol is wordBoundsAtCol sliced at its one caller; seamIdxAt is mouse.zig's own (events.zig's comment names reportRange)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/mouse.zig')
| -rw-r--r-- | src/mouse.zig | 44 |
1 files changed, 13 insertions, 31 deletions
diff --git a/src/mouse.zig b/src/mouse.zig index 02e3b6a5..1292c06f 100644 --- a/src/mouse.zig +++ b/src/mouse.zig @@ -28,7 +28,6 @@ const BOX_H = pardes.BOX_H; const TAG_GAP = pardes.TAG_GAP; const TAG_TEXT_INSET = pardes.TAG_TEXT_INSET; const Builtin = pardes.Builtin; -const wordAtCol = pardes.wordAtCol; const Mouse = pardes.Mouse; const sel_slot = pardes.sel_slot; const Pardes = pardes.Pardes; @@ -134,7 +133,8 @@ fn headerSweepRun(p: *Pardes, sweep: HeaderSweep) void { const at = swept.lo - start; const focused = p.header_focus and p.header_column == column; const on = if (focused) tagline.headerSelection(t, text, line) else null; - break :click if (on) |sp| (if (at >= sp.lo and at < sp.hi) bar[sp.lo..sp.hi] else wordAtCol(bar, at)) else wordAtCol(bar, at); + const under = if (pardes.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; }; const word = p.scratch.allocator().dupe(u8, selected) catch return; tagline.exitHeader(p); @@ -306,7 +306,7 @@ pub fn bodyHitForPane(p: *const Pardes, id: usize, supplied: Mouse.BodyHit, clam mapped_hit.pixel_x = std.math.clamp(mapped_hit.pixel_x, x0, @max(x0, x1 - 0.001)); mapped_hit.pixel_y = std.math.clamp(mapped_hit.pixel_y, y0, @max(y0, y1 - 0.001)); } - return p.reprojectBodyHit(mapped_hit); + return Layer.bodyAgain(mapped_hit); } fn bodyPlace(hit: ?Mouse.BodyHit, pane: *const Pane) ?Layer.Place { @@ -612,22 +612,16 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void { } } if (p.header_drag and m.button == config.select_button and (m.kind == .drag or m.kind == .release)) { - const t = tagline.focusedHeader(p) orelse { + if (tagline.focusedHeader(p) == null) { p.header_drag = false; return; - }; - const x = if (p.header_column) |c| p.col_x[c] + TAG_TEXT_INSET else TAG_TEXT_INSET; - const text = edit.flatSurface(p, t) catch return; - // `row` is the header's row on screen, `line` the line of its text - // shown there. - const base = if (p.header_column != null) p.topBarHeight() else 0; - const row: u16 = @intCast(@min(mrow -| base, (if (p.header_column != null) p.columnBarHeight() else p.topBarHeight()) -| 1)); - const line: u16 = @intCast(@min(row + p.header_top, modal.lineCount(text) -| 1)); - const bar = modal.lineSlice(text, line); - const at = @min(bar.len, panes.File.rawAtDisplay(bar, (Layer.columnAt(p, if (p.header_column != null) .column else .workspace, p.header_column orelse 0, p.pointer_tag_hit, p.header_drag, row) orelse (mcol -| x)) + p.header_scroll)); - // the anchor stays where the press put it - t.cur_row = line; - t.cur_col = @intCast(at); + } + // Held to the focused header's rows and text; the anchor stays + // where the press put it. + const point = headerPoint(p, p.header_column, mcol, mrow, true) orelse return; + const t = point.t; + 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; return; @@ -902,7 +896,7 @@ 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. -pub fn seamIdxAt(p: *const Pardes, c: usize, mrow: u16) ?usize { +fn seamIdxAt(p: *const Pardes, c: usize, mrow: u16) ?usize { if (c >= p.ncol) return null; for (0..p.col_n[c] -| 1) |k| if (mrow == seamRowOf(p, c, k)) return k; return null; @@ -996,18 +990,6 @@ pub fn dragUpdate(p: *Pardes, mcol: u16, mrow: u16, body_hit: ?Mouse.BodyHit) vo } } -fn reportGesture( - p: *Pardes, - id: usize, - cmd: Builtin, - text: []const u8, - on_tag: bool, - operand: exec.PointerOperand, - chord_arg: ?[]const u8, -) bool { - return reportRange(p, id, cmd, text, on_tag, gestureRange(p, id, text, on_tag, operand), chord_arg); -} - /// Whether a script reads pane `id`'s events, and so takes its looks and /// execs: the 9P server's, the authority's alone (a replica has its /// answer, `tape.authority`). @@ -1122,7 +1104,7 @@ pub fn dispatchPointerBuiltin( // 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. const operand = text orelse return; - if (gesture) |g| if (reportGesture(p, id, cmd, operand, g.on_tag, g.operand, arg)) return; + if (gesture) |g| if (reportRange(p, id, cmd, operand, g.on_tag, gestureRange(p, id, operand, g.on_tag, g.operand), arg)) return; // B2 anywhere on a query pane's line 1 is the line: run again, whatever // word of it was clicked (Query.zig). if (gesture) |g| if (!g.on_tag and g.operand.row == 0 and cmd == config.exec_cmd) if (p.panes[id]) |pane| if (pane.query) |q| { |
