summaryrefslogtreecommitdiff
path: root/src/mouse.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-22 09:50:43 -0300
committerGabriel Schneider <[email protected]>2026-10-22 10:03:24 -0300
commita8b457a306a4442975210bcac3f04b56513c61c3 (patch)
tree6e2026ecb15da2fb919a0202f5d8b38e3b36a595 /src/mouse.zig
parenta8a1499bdffffc5b6919e24ec957e92fabaf003b (diff)
parent7e9d2c4169245072265b483ffaa6aa05f23f08d3 (diff)
downloadpardes-a8b457a306a4442975210bcac3f04b56513c61c3.tar.gz
pardes-a8b457a306a4442975210bcac3f04b56513c61c3.zip
Merge: Def/Refs, the diff viewer, Helix n/N, Callstack, Zig 0.17, Window mode and the terminal cwd fix onto 0.24
The docs keep both sides: 0.24's Ctrl-i fallbacks and typed ls with this line's Window mode, raw Esc and Helix n/N wording. The CHANGELOG's unreleased entries go above 0.24, Def/Refs and the context rows among them. cheatsheet-a4.pdf rendered again; .scratch/ ignored. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/mouse.zig')
-rw-r--r--src/mouse.zig47
1 files changed, 28 insertions, 19 deletions
diff --git a/src/mouse.zig b/src/mouse.zig
index 8020fda8..76c65a16 100644
--- a/src/mouse.zig
+++ b/src/mouse.zig
@@ -100,7 +100,7 @@ pub const HeaderSweep = struct {
/// as a pane tag's sweep stays on its tag.
fn headerPoint(p: *Pardes, column: ?usize, mcol: u16, mrow: u16, clamp: bool) ?struct { t: *panes.Text, text: []const u8, line: u16, at: usize } {
const t = if (column) |c| &p.col_tags[c] else &p.global_tag;
- const x = if (column) |c| p.col_x[c] + TAG_TEXT_INSET else 0;
+ const x = if (column) |c| p.col_x[c] + TAG_TEXT_INSET else TAG_TEXT_INSET;
const focused = p.header_focus and p.header_column == column;
const text = edit.flatSurface(p, t) catch return null;
const base = if (column != null) p.topBarHeight() else 0;
@@ -379,7 +379,7 @@ fn programMouse(p: *Pardes, m: Mouse) bool {
.none => null,
else => return false,
};
- const bit: u3 = if (button) |b| @as(u3, 1) << @intCast(@intFromEnum(b)) else 0;
+ const bit: u3 = if (button) |b| @as(u3, 1) << @intCast(@backingInt(b)) else 0;
const at = p.presentation.pointer(p.screen_w, p.screen_h, @min(m.col, p.screen_w -| 1), @min(m.row, p.screen_h -| 1));
var mods: panes.terminal.MouseMods = .{ .shift = m.shift, .alt = m.alt, .ctrl = m.ctrl };
var buf: [64]u8 = undefined;
@@ -465,6 +465,7 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void {
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.
+ if (m.kind == .press) p.window_pick = null;
if (m.kind == .press and switch (m.button) {
.left, .middle, .right => true,
else => false,
@@ -588,7 +589,7 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void {
p.header_drag = false;
return;
};
- const x = if (p.header_column) |c| p.col_x[c] + TAG_TEXT_INSET else 0;
+ 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.
@@ -612,7 +613,8 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void {
pane.closePrompt();
};
var column: ?usize = null;
- var x: u16 = 0;
+ var x: u16 = TAG_TEXT_INSET;
+ if (mcol < x) return;
if (mrow >= p.topBarHeight()) {
for (0..p.ncol) |c| if (mcol >= p.col_x[c] and mcol < p.col_x[c] + p.col_w[c]) {
column = c;
@@ -700,7 +702,7 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void {
// look; the rest of the gesture is inert
if (p.drag == .select and p.drag.select.button == config.look_button) {
if (p.panes[p.drag.select.id]) |t| {
- t.sel[@intFromEnum(config.look_button)].state = .none;
+ t.sel[@backingInt(config.look_button)].state = .none;
if (comptime pdf_enabled)
panes.Pdf.pointerCancel(t, p.drag.select.pdf);
}
@@ -811,7 +813,7 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void {
// an execute or look drag cancels it (textselect23's mask)
if (p.drag == .select) {
if (p.panes[p.drag.select.id]) |t| {
- t.sel[@intFromEnum(p.drag.select.button)].state = .none;
+ t.sel[@backingInt(p.drag.select.button)].state = .none;
if (comptime pdf_enabled)
panes.Pdf.pointerCancel(t, p.drag.select.pdf);
}
@@ -832,8 +834,8 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void {
pane.scrollBy(if (m.button == config.look_button) local else -local);
} else if (edit.pointerTextSelection(p, id, mcol, mrow, m.body_hit, p.pointer_tag_hit)) |pointed| {
if (m.button == config.look_button) p.active = id;
- pane.clearPointerSelection(@intFromEnum(m.button));
- pane.sel[@intFromEnum(m.button)] = pointed.sel;
+ pane.clearPointerSelection(@backingInt(m.button));
+ pane.sel[@backingInt(m.button)] = pointed.sel;
p.drag = .{
.select = .{
.id = id,
@@ -905,7 +907,7 @@ pub fn dragUpdate(p: *Pardes, mcol: u16, mrow: u16, body_hit: ?Mouse.BodyHit) vo
.select => |*s| {
if (p.panes[s.id]) |pane| {
const r = p.rects[s.id];
- const b = @intFromEnum(s.button);
+ const b = @backingInt(s.button);
const tag_rows: i32 = pane.tag_rows;
if (pane.body_rows > 0 and pane.sel[b].r0 >= tag_rows) if (body_hit) |supplied| {
const mapped_hit = bodyHitForPane(p, s.id, supplied, true) orelse return;
@@ -1047,7 +1049,7 @@ fn gestureRange(p: *Pardes, id: usize, text: []const u8, on_tag: bool, operand:
const top = lead[0] - @as(i32, pane.tag_rows);
if (top < 0) break :lead null;
const w = pane.wrapAt(top);
- const col = edit.paneByteAtDisplay(p, &pane.body, w.line, w.at, lead[1] - panes.File.gutterWidth(pane));
+ const col = edit.paneByteAtDisplay(p, &pane.body, w.line, w.at, lead[1] - panes.File.gutterWidth(pane) - w.pad);
break :lead .{
.row = @intCast(@max(0, w.line)),
.col = @intCast(@max(0, col)),
@@ -1154,7 +1156,7 @@ fn sweepPoint(p: *Pardes, pane: *panes.Pane, r: i32, c: i32) ?modal.Cursor {
if (visible < 0) return null;
const w = pane.wrapAt(visible);
if (w.line < 0) return null;
- const col = edit.paneByteAtDisplay(p, &pane.body, w.line, w.at, c - (if (pane.file != null) @as(i32, panes.File.gutterWidth(pane)) else 0));
+ const col = edit.paneByteAtDisplay(p, &pane.body, w.line, w.at, c - w.pad - (if (pane.file != null) @as(i32, panes.File.gutterWidth(pane)) else 0));
return .{ .row = @intCast(w.line), .col = @intCast(@max(0, col)) };
}
@@ -1234,10 +1236,10 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void {
}
if (s.chorded) {
// a cut/paste chord consumed this drag; the release is inert
- pane.sel[@intFromEnum(s.button)].state = .none;
+ pane.sel[@backingInt(s.button)].state = .none;
return;
}
- const b = @intFromEnum(s.button);
+ const b = @backingInt(s.button);
pane.sel[b].state = .done;
if (s.button == config.select_button) {
const sl = pane.sel[sel_slot];
@@ -1268,7 +1270,7 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void {
&pane.body,
w.line,
w.at,
- sl.c1 - (if (pane.file != null) @as(i32, panes.File.gutterWidth(pane)) else 0),
+ sl.c1 - w.pad - (if (pane.file != null) @as(i32, panes.File.gutterWidth(pane)) else 0),
);
pane.body.cur_pinned = true;
if (edit.clampFileCursor(&pane.body)) pane.ensureCursorVisible();
@@ -1288,7 +1290,7 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void {
pane.sel[sel_slot].state = .none;
pane.body.vsel = .{ .active = true, .row = @intCast(a.row), .col = @intCast(a.col), .explicit = true };
};
- if (s.ctrl) p.lspRequest(s.id, .definition, "");
+ if (s.ctrl) exec.runBuiltin(p, .Def, s.id, "", null);
}
} else {
const clk = pane.sel[b];
@@ -1312,7 +1314,14 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void {
pane.sel[b] = expanded
else if (operand.text == null)
pane.sel[b].state = .none;
- if (s.button == config.look_button and clk.r0 >= pane.tag_rows and pane.body.mode != .tty) {
+ if (s.button == config.look_button and clk.r0 >= pane.tag_rows and pane.body.mode != .tty and operand.expanded != null) {
+ // This click chose a new word. An old keyboard anchor
+ // must not stretch to it; borrowed selections retain
+ // their original cursor and extent.
+ pane.body.vsel.active = false;
+ pane.body.msel.active = false;
+ pane.body.nsel = 0;
+ pane.body.select = false;
pane.body.cur_row = operand.row;
pane.body.cur_col = operand.col;
if (edit.clampFileCursor(&pane.body)) pane.ensureCursorVisible();
@@ -1431,8 +1440,8 @@ fn chordCutPaste(p: *Pardes, cut: bool) void {
const w1 = pane.wrapAt(@max(0, sl.r1 - @as(i32, pane.tag_rows)));
const row0 = w0.line;
const row1 = w1.line;
- const col0 = edit.paneByteAtDisplay(p, &pane.body, w0.line, w0.at, sl.c0 - pfx);
- const col1 = edit.paneByteAtDisplay(p, &pane.body, w1.line, w1.at, sl.c1 - pfx);
+ const col0 = edit.paneByteAtDisplay(p, &pane.body, w0.line, w0.at, sl.c0 - pfx - w0.pad);
+ const col1 = edit.paneByteAtDisplay(p, &pane.body, w1.line, w1.at, sl.c1 - pfx - w1.pad);
pane.body.cur_row = row1;
pane.body.cur_col = col1;
pane.body.cur_pinned = true;
@@ -1493,7 +1502,7 @@ test "plain left click clears explicit modal selection" {
try std.testing.expectEqual(@as(i32, 3), pane.body.cur_col);
try std.testing.expect(!pane.body.vsel.active);
try std.testing.expect(!pane.body.msel.active);
- try std.testing.expectEqual(.none, pane.sel[@intFromEnum(config.select_button)].state);
+ try std.testing.expectEqual(.none, pane.sel[@backingInt(config.select_button)].state);
}
test "selection drag and queued release do not enter panel pending state" {