summaryrefslogtreecommitdiff
path: root/core/mouse.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/mouse.zig')
-rw-r--r--core/mouse.zig70
1 files changed, 51 insertions, 19 deletions
diff --git a/core/mouse.zig b/core/mouse.zig
index 04bbaeb4..2e55ba95 100644
--- a/core/mouse.zig
+++ b/core/mouse.zig
@@ -726,6 +726,15 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void {
if (m.kind == .press) {
tagline.exitHeader(p);
}
+ // A press on a tag out of rest ends its state as Esc does, the bodies
+ // back, then does what a press there does at rest: the tag is drawn as
+ // at rest, and its words act as they do then (UX DESIGN M3). A pane made
+ // for a picker goes with it, and the press with it: it was the Esc.
+ if (m.kind == .press) if (hostTagAt(p, mcol, mrow)) |id| {
+ const serial = p.panes[id].?.serial;
+ pardes.TagState.toRest(p);
+ if (p.paneBySerial(serial) == null) return;
+ };
if (m.kind == .press) if (bandPoint(p, mcol, mrow)) |point| return bandPress(p, m.button, point);
switch (m.button) {
@@ -920,30 +929,43 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void {
}
}
-/// 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).
+/// The pane out of rest whose tag (its rows at rest, Band.covered) a press
+/// is on: a window's layer hit, or a grid cell.
+fn hostTagAt(p: *Pardes, mcol: u16, mrow: u16) ?usize {
+ const v = p.view();
+ const id = pardes.TagState.hostOf(p) orelse return null;
+ if (v.pointer_tag_hit) |hit| return if (hit.kind == .pane and hit.id == id) id else null;
+ if (paneAt(p, mcol, mrow) != id) return null;
+ const pane = p.panes[id].?;
+ const top = p.tagTop(pane, v.rects[id]);
+ return if (mrow >= top and mrow < top + pardes.Band.covered(p, pane, id).tag) id else null;
+}
+
+/// A head's row (`head`) or a band's under it, drawn over the body: a
+/// covered row belongs to them, never to the body under it (UX DESIGN I1,
+/// M2).
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, or the
-/// head's row over the body: a window's layer hit, or a grid cell under a
-/// tag's own rows.
+/// The head's or the band's row and column (at the tagline's pitch) a
+/// press is on: a window's layer hit, or a grid cell under a tag.
fn bandPoint(p: *Pardes, mcol: u16, mrow: u16) ?BandPoint {
const v = p.view();
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;
+ if (hit.kind != .band) return null;
+ const pane = (if (hit.id < p.panes.len) p.panes[hit.id] else null) orelse return null;
+ const head = pardes.Band.covered(p, pane, hit.id).head;
+ if (hit.line < head) return .{ .id = hit.id, .line = hit.line, .col = hit.col, .head = true };
+ return .{ .id = hit.id, .line = hit.line - head, .col = hit.col };
}
const id = paneAt(p, mcol, mrow) orelse return null;
const pane = p.panes[id].?;
const at = pardes.Band.covered(p, pane, id);
const r = v.rects[id];
- 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 top = p.tagTop(pane, r) + at.tag;
+ if (mrow < top or mrow >= top + at.over 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 };
+ if (mrow < top + at.head) return .{ .id = id, .line = mrow - top, .col = col, .head = true };
+ return .{ .id = id, .line = mrow - top - at.head, .col = col };
}
/// A press on a band (Band.zig), read-only text: the select button puts
@@ -952,14 +974,24 @@ 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.
+ // The head's rows: the select button in its field puts the field's
+ // caret there (UX DESIGN M6); its words run and are looked at as a
+ // tag's.
if (point.head) {
+ const h = (pardes.TagState.head(p, arena, p.panes[point.id].?) catch return) orelse return;
+ const shown = tagline.wrapTag(p.settings.tab, arena, h.text, tagline.tagWidth(p, point.id)) catch return;
+ const text = modal.lineSlice(shown.text, point.line);
+ const raw = panes.File.rawAtDisplay(p.settings.tab, text, point.col);
+ if (button == config.select_button) {
+ const caret = h.caret orelse return;
+ const field = &v.tag_state.field;
+ const at = shown.toReal(modal.lineStartOffset(shown.text, point.line) + modal.graphemeStart(text, raw));
+ const start = caret - field.caret;
+ if (at >= start and at <= start + field.len) field.caret = @intCast(at - start);
+ return;
+ }
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;
+ const b = tagline.wordBoundsAtCol(text, raw) 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);