summaryrefslogtreecommitdiff
path: root/core/mouse.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/mouse.zig')
-rw-r--r--core/mouse.zig66
1 files changed, 64 insertions, 2 deletions
diff --git a/core/mouse.zig b/core/mouse.zig
index aab8a752..b6e99300 100644
--- a/core/mouse.zig
+++ b/core/mouse.zig
@@ -706,6 +706,7 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void {
if (m.kind == .press) {
tagline.exitHeader(p);
}
+ if (m.kind == .press) if (bandPoint(p, mcol, mrow)) |point| return bandPress(p, m.button, point);
switch (m.button) {
.none, .back, .forward => {}, // hover and navigation handled above
@@ -886,6 +887,55 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void {
}
}
+const BandPoint = struct { id: usize, line: u16, col: u16 };
+
+/// The band row and column (at the tagline's pitch) a press is on: a
+/// window's layer hit, or a terminal's grid cell under a tag's text rows.
+fn bandPoint(p: *Pardes, mcol: u16, mrow: u16) ?BandPoint {
+ const v = p.view();
+ if (v.pointer_tag_hit) |hit| return if (hit.kind == .band) .{ .id = hit.id, .line = hit.line, .col = hit.col } else null;
+ const id = paneAt(p, mcol, mrow) orelse return null;
+ const pane = p.panes[id].?;
+ if (pane.band_rows == 0) return null;
+ const r = v.rects[id];
+ const top = p.tagTop(pane, r) + (pane.tag_rows - pane.band_rows);
+ if (mrow < top or mrow >= top + pane.band_rows or mcol < r.x + TAG_TEXT_INSET) return null;
+ return .{ .id = id, .line = mrow - top, .col = mcol - (r.x + TAG_TEXT_INSET) };
+}
+
+/// A press on a band (Band.zig), read-only text: the select button puts
+/// the rows' cursor on the row it is on; execute runs the word under it
+/// and look looks at it, as on a tag, the tag back at rest first.
+fn bandPress(p: *Pardes, button: Mouse.Button, point: BandPoint) void {
+ const v = p.view();
+ const arena = p.scratch.allocator();
+ if (button == config.select_button) {
+ const band = (pardes.Band.of(p, arena, p.panes[point.id].?, point.id) catch return) orelse return;
+ const ln = band.line(arena, p.settings.tab, point.line) catch return;
+ for (ln.parts) |part| if (point.col >= part.col -| 2 and point.col < part.col + part.width) {
+ pardes.TagState.point(p, part.row.index);
+ };
+ return;
+ }
+ if (button != config.exec_button and button != config.look_button) return;
+ const word = (pardes.Band.wordAt(p, arena, point.id, point.line, point.col) catch return) orelse return;
+ const kept = arena.dupe(u8, word) catch return;
+ // A picker's band: B2 runs the word with the picker live (an act's word
+ // acts, Pick.execWord); B3 on a row lands on it.
+ if (v.tag_state.kind == .pick) {
+ if (button == config.exec_button) return exec.runBuiltin(p, config.exec_cmd, v.active, "", kept);
+ const band = (pardes.Band.of(p, arena, p.panes[point.id].?, point.id) catch return) orelse return;
+ const ln = band.line(arena, p.settings.tab, point.line) catch return;
+ for (ln.parts) |part| if (point.col >= part.col and point.col < part.col + part.width) {
+ pardes.TagState.point(p, part.row.index);
+ return pardes.Pick.landHere(p);
+ };
+ return;
+ }
+ pardes.TagState.toRest(p);
+ exec.runBuiltin(p, if (button == config.exec_button) config.exec_cmd else config.look_cmd, v.active, "", kept);
+}
+
/// 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 {
@@ -1226,8 +1276,12 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void {
// click on the path, if it can be renamed, drafts a name.
const row: usize = @intCast(@max(0, sl.r1));
const col: usize = @intCast(@max(0, sl.c1));
- if (!dragged and tagline.onName(p.settings.tab, pane, row, col)) {
- tagline.draftName(p, pane, col);
+ // A plain click on a word of its walk is its Look
+ // (pick-ui SPEC ยง6.3): the one place B1 does more than
+ // select.
+ if (!dragged and tagline.trailClick(p, s.id, row, col, false)) return;
+ if (if (dragged) null else tagline.onName(p.settings.tab, pane, row, col)) |at| {
+ tagline.draftName(p, pane, at);
} else if (tagline.tagOffsetAt(p, pane, row, col)) |cursor| {
pane.tag.cur_row = @intCast(cursor.row);
pane.tag.cur_col = @intCast(cursor.col);
@@ -1293,6 +1347,14 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void {
return;
}
};
+ // On a word of the tag's walk: that step's Look or Exec
+ // (Trail.zig), not the word's.
+ if (clk.r0 >= 0 and clk.r0 < pane.tag_rows and clk.r0 == clk.r1 and clk.c0 == clk.c1 and clk.c0 >= 0 and
+ tagline.trailClick(p, s.id, @intCast(clk.r0), @intCast(clk.c0), s.button == config.exec_button))
+ {
+ pane.sel[b].state = .none;
+ return;
+ }
var operand = exec.operandAt(p, pane, clk, true, s.button == config.look_button);
if (operand.expanded) |expanded|
pane.sel[b] = expanded