summaryrefslogtreecommitdiff
path: root/core/mouse.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/mouse.zig')
-rw-r--r--core/mouse.zig41
1 files changed, 32 insertions, 9 deletions
diff --git a/core/mouse.zig b/core/mouse.zig
index 72f599dd..b62cec7e 100644
--- a/core/mouse.zig
+++ b/core/mouse.zig
@@ -911,21 +911,30 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void {
}
}
-const BandPoint = struct { id: usize, line: u16, col: u16 };
+/// A band's row, or a head's row past its tag's own (`head`), drawn over
+/// the body: a covered row belongs to the band, never to the body under it
+/// (UX DESIGN I1).
+const BandPoint = struct { id: usize, line: u16, col: u16, head: bool = false };
-/// The band row and column (at the tagline's pitch) a press is on: a
-/// window's layer hit, or a terminal's grid cell under a tag's text rows.
+/// The band row and column (at the tagline's pitch) a press is on, or the
+/// head's row over the body: a window's layer hit, or a grid cell under a
+/// tag's own rows.
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;
+ if (v.pointer_tag_hit) |hit| {
+ if (hit.kind == .band) return .{ .id = hit.id, .line = hit.line, .col = hit.col };
+ const pane = (if (hit.kind == .pane and hit.id < p.panes.len) p.panes[hit.id] else null) orelse return null;
+ return if (hit.line >= pane.tag_rows) .{ .id = hit.id, .line = hit.line, .col = hit.col, .head = true } else null;
+ }
const id = paneAt(p, mcol, mrow) orelse return null;
const pane = p.panes[id].?;
- const rows = pardes.Band.shownRows(p, pane, id);
- if (rows == 0) return null;
+ const at = pardes.Band.covered(p, pane, id);
const r = v.rects[id];
- const top = p.tagTop(pane, r) + (pane.tag_rows - pane.band_rows);
- if (mrow < top or mrow >= top + rows or mcol < r.x + TAG_TEXT_INSET) return null;
- return .{ .id = id, .line = mrow - top, .col = mcol - (r.x + TAG_TEXT_INSET) };
+ const top = p.tagTop(pane, r);
+ if (mrow < top + @min(pane.tag_rows, at.text) or mrow >= top + at.text + at.band or mcol < r.x + TAG_TEXT_INSET) return null;
+ const col = mcol - (r.x + TAG_TEXT_INSET);
+ if (mrow < top + at.text) return .{ .id = id, .line = mrow - top, .col = col, .head = true };
+ return .{ .id = id, .line = mrow - top - at.text, .col = col };
}
/// A press on a band (Band.zig), read-only text: the select button puts
@@ -934,6 +943,20 @@ fn bandPoint(p: *Pardes, mcol: u16, mrow: u16) ?BandPoint {
fn bandPress(p: *Pardes, button: Mouse.Button, point: BandPoint) void {
const v = p.view();
const arena = p.scratch.allocator();
+ // A head's row over the body: its words as the tag's first row's.
+ if (point.head) {
+ if (button != config.exec_button and button != config.look_button) return;
+ const shown = (tagline.shownTag(p, arena, p.panes[point.id].?) catch return).text;
+ var lines = std.mem.splitScalar(u8, shown, '\n');
+ for (0..point.line) |_| _ = lines.next();
+ const text = lines.next() orelse return;
+ const b = tagline.wordBoundsAtCol(text, panes.File.rawAtDisplay(p.settings.tab, text, point.col)) orelse return;
+ if (b.lo == b.hi) return;
+ const word = text[b.lo..b.hi];
+ if (v.tag_state.kind == .pick and button == config.exec_button) return exec.runBuiltin(p, config.exec_cmd, v.active, "", word);
+ pardes.TagState.toRest(p);
+ return exec.runBuiltin(p, if (button == config.exec_button) config.exec_cmd else config.look_cmd, v.active, "", word);
+ }
if (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;