summaryrefslogtreecommitdiff
path: root/core/mouse.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/mouse.zig')
-rw-r--r--core/mouse.zig51
1 files changed, 42 insertions, 9 deletions
diff --git a/core/mouse.zig b/core/mouse.zig
index 400d020b..89a8c5c6 100644
--- a/core/mouse.zig
+++ b/core/mouse.zig
@@ -499,6 +499,17 @@ fn chordCutPaste(p: *Pardes, cut: bool) edit.Error!void {
pub fn handleMouse(p: *Pardes, event: Mouse) void {
const v = p.view();
+ // A click that gives the keyboard to another pane ends the level or
+ // typing state of the tag out of rest as Esc does, its text's prefix
+ // with it (SPEC §3.4.6: only the pane with the keyboard leaves rest);
+ // one in its band or its own tag keeps it.
+ const host = pardes.TagState.hostOf(p);
+ defer if (host) |was| if (v.active != was) {
+ const to = v.active;
+ v.active = was;
+ pardes.TagState.toRest(p);
+ v.active = to;
+ };
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.
@@ -581,6 +592,21 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void {
v.hover_col = mcol;
v.hover_row = mrow;
+ // The notice row: the execute or the look button on a word there runs
+ // it or Looks at it, as on a header (a place a message names, its
+ // cause); nothing else happens on it.
+ const foot = layout.noticeRowHeight(p);
+ if (foot > 0 and mrow >= v.screen_h - foot and v.drag == .none and v.header_sweep == null and !v.header_drag) {
+ if (m.kind != .press or (m.button != config.exec_button and m.button != config.look_button)) return;
+ var buf: [pardes.Messages.notice_row_cap]u8 = undefined;
+ const row = pardes.Messages.noticeRow(p, layout.tagCapacity(p, v.screen_w -| TAG_TEXT_INSET) -| 1, &buf);
+ const col = Layer.columnAt(p, .notice_row, 0, v.pointer_tag_hit, false, 0) orelse (mcol -| TAG_TEXT_INSET);
+ const bounds = tagline.wordBoundsAtCol(row.text, panes.File.rawAtDisplay(p.settings.tab, row.text, col)) orelse return;
+ const word = p.scratch.allocator().dupe(u8, row.text[bounds.lo..bounds.hi]) catch |err| return p.reportError(.at(v.active), "notice row", err);
+ if (m.button == config.exec_button) _ = exec.execute(p, v.active, word) else exec.runBuiltin(p, config.look_cmd, v.active, "", word);
+ return;
+ }
+
const hovered = paneAt(p, mcol, mrow);
// any press that is NOT the execute+select chord abandons a pending
@@ -851,6 +877,13 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void {
pane.scrollBy(p.settings.tab, if (m.button == config.look_button) local else -local);
} 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;
+ // A word of a message's detail, read as it is drawn:
+ // run or looked at as a typed one would be.
+ if (pointed.ghost) |row| {
+ const arena = p.scratch.allocator();
+ const word = (body_layer.wordAt(p, arena, id, row, @intCast(@max(0, pointed.sel.c0))) catch return) orelse return;
+ return exec.runBuiltin(p, if (m.button == config.exec_button) config.exec_cmd else config.look_cmd, id, "", arena.dupe(u8, word) catch return);
+ }
pane.clearPointerSelection(@backingInt(m.button));
pane.sel[@backingInt(m.button)] = pointed.sel;
v.drag = .{
@@ -963,7 +996,7 @@ pub fn dragUpdate(p: *Pardes, mcol: u16, mrow: u16, body_hit: ?Mouse.BodyHit) vo
if (supplied.serial == pane.serial) s.body = supplied.place;
const mapped_hit = bodyHitForPane(p, s.id, supplied, true) orelse return;
pane.sel[b].c1 = @as(i32, mapped_hit.col) - config.GUTTER;
- pane.sel[b].r1 = @as(i32, mapped_hit.row) + tag_rows;
+ pane.sel[b].r1 = pane.textRow(mapped_hit.row) + tag_rows;
return;
};
// A sweep that began on the tag stays on it, on the tag line
@@ -988,9 +1021,9 @@ pub fn dragUpdate(p: *Pardes, mcol: u16, mrow: u16, body_hit: ?Mouse.BodyHit) vo
else if (mrow < body_y)
-1
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 >= v.screen_h and mrow + 1 >= body_y + body_h))
+ // The pointer cannot leave the screen: at a bottom pane
+ // (over the notice row), its last row is the edge.
+ (body_y + body_h + layout.noticeRowHeight(p) >= v.screen_h and mrow + 1 >= body_y + body_h))
1
else
0;
@@ -999,7 +1032,7 @@ pub fn dragUpdate(p: *Pardes, mcol: u16, mrow: u16, body_hit: ?Mouse.BodyHit) vo
else if (body_h == 0)
0
else
- @as(i32, @min(@max(mrow, body_y), body_y + body_h - 1)) - @as(i32, body_y) + tag_rows;
+ pane.textRow(@as(i32, @min(@max(mrow, body_y), body_y + body_h - 1)) - @as(i32, body_y)) + tag_rows;
if (pane.sel[b].r1 < tag_rows) pane.sel[b].c1 += @as(i32, pane.tag_scroll);
}
},
@@ -1265,7 +1298,7 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void {
// (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| {
+ if (if (dragged) null else tagline.onName(p, 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);
@@ -1600,12 +1633,12 @@ test "a chorded exec an event reader holds is told with its argument, and writte
const line = try std.fmt.bufPrint(&back, "M{s}", .{records[0][1..]});
try std.testing.expectEqual(ctlfs.Status.ok, th.call(p, .{ .tag = 3, .op = .write, .node = event, .handle = h, .data = line }).reply.status);
const pane = p.panes[0].?;
- try std.testing.expectEqualStrings("arg-text", pane.msg[0..pane.msg_len]);
+ try std.testing.expectEqualStrings("arg-text", p.messages.saidBy(pane));
// All three records written back as read, in one write or in three:
// the two after the first are its argument and where it came from,
// never commands of their own.
for ([_]bool{ true, false }) |together| {
- pane.msg_len = 0;
+ p.messages.live_len = 0;
var all: [256]u8 = undefined;
var w = std.Io.Writer.fixed(&all);
for (records) |r| try w.print("M{s}", .{r[1..]});
@@ -1615,7 +1648,7 @@ test "a chorded exec an event reader holds is told with its argument, and writte
var one: [80]u8 = undefined;
_ = th.call(p, .{ .tag = 6, .op = .write, .node = event, .handle = h, .data = try std.fmt.bufPrint(&one, "M{s}", .{r[1..]}) });
}
- try std.testing.expectEqualStrings("arg-text", pane.msg[0..pane.msg_len]);
+ try std.testing.expectEqualStrings("arg-text", p.messages.saidBy(pane));
try std.testing.expect(!th.logHas(p, "run "));
}
_ = th.call(p, .{ .tag = 4, .op = .release, .node = event, .handle = h });