From c4cb26fe6f061dd4bcfb9e9df7b7d4e4d434d10a Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 7 Jul 2026 22:12:33 -0300 Subject: acme mouse chords: 1-2 Cut / 1-3 Paste while a left selection drag holds (both in one hold = Snarf/copy; the chorded left release is inert), plus 2-3 / 3-1 / 3-2 cancel an execute or look drag mid-gesture (the 2-1 argument chord already existed). chordcut.snap covers cut/copy/paste and both cancels; tutor documents the chords. --- src/pardes.zig | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 89 insertions(+), 1 deletion(-) (limited to 'src/pardes.zig') diff --git a/src/pardes.zig b/src/pardes.zig index f647ed00..9397f445 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -659,7 +659,9 @@ const Drag = union(enum) { border_v: struct { left_col: usize, cur_x: u16 }, border_h: struct { col: usize, top_idx: usize, cur_y: u16 }, move: struct { id: usize, cur_x: u16, cur_y: u16 }, - select: struct { id: usize, button: Mouse.Button }, + /// chorded: a 1-2/1-3 cut/paste chord fired during this left drag — + /// the drag's own release is then inert + select: struct { id: usize, button: Mouse.Button, chorded: bool = false }, }; const Rect = struct { x: u16, y: u16, w: u16, h: u16 }; @@ -3549,6 +3551,13 @@ pub const Pardes = struct { } return; } + // acme 3-1: a left tap during a right (look) drag cancels + // the look; the rest of the gesture is inert + if (p.drag == .select and p.drag.select.button == .right) { + if (p.panes[p.drag.select.id]) |t| t.sel[@intFromEnum(Mouse.Button.right)].state = .none; + p.drag = .none; + return; + } if (mrow < TOPBAR_H) return; // topbar: left click deliberately inert // resize handles first: a pane's own trailing edge (v: the // left column's last col; h: the upper pane's last row) @@ -3596,6 +3605,19 @@ pub const Pardes = struct { }, .middle, .right => switch (m.kind) { .press => { + // acme 1-2 / 1-3: middle (Cut) or right (Paste) tapped + // while the left button holds a selection drag + if (p.drag == .select and p.drag.select.button == .left) { + p.chordCutPaste(m.button == .middle); + return; + } + // acme 2-3 / 3-2: tapping the OTHER of middle/right during + // 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; + p.drag = .none; + return; + } if (mrow < TOPBAR_H) { // global tagbar: MIDDLE runs the command under the click // (a stray left click must never Kill) @@ -3713,6 +3735,11 @@ pub const Pardes = struct { }, .select => |s| { const pane = p.panes[s.id] orelse return; + if (s.chorded) { + // a cut/paste chord consumed this drag; the release is inert + pane.sel[@intFromEnum(s.button)].state = .none; + return; + } const b = @intFromEnum(s.button); pane.sel[b].state = .done; if (s.button == .left) { @@ -3749,6 +3776,67 @@ pub const Pardes = struct { } } + /// acme 1-2 (Cut) / 1-3 (Paste): middle or right tapped while the left + /// button holds a selection drag. The first tap converts the mouse + /// selection into the modal one (vsel anchored at the drag start, cursor + /// at its end; a plain click is a bare cursor). Cut yanks + deletes the + /// selection; Paste replaces it with the yank register, or splices the + /// register in literally at a bare cursor — so 1-2 then 1-3 in one hold + /// nets out to Snarf (copy: the text returns, the register keeps it). + fn chordCutPaste(p: *Pardes, cut: bool) void { + const s = &p.drag.select; + const pane = p.panes[s.id] orelse return; + if (!s.chorded) { + s.chorded = true; + const sl = pane.sel[0]; + pane.sel[0].state = .none; + if (pane.mode == .tty) return; // the pty owns the cursor there + const pfx: i32 = if (pane.file != null) PREFIX_W else 0; + const hs: i32 = if (pane.file != null) pane.hscroll else 0; + const row0 = @max(0, sl.r0 - @as(i32, BOX_H)) + pane.scroll(); + const row1 = @max(0, sl.r1 - @as(i32, BOX_H)) + pane.scroll(); + const col0 = @max(0, sl.c0 - pfx) + hs; + const col1 = @max(0, sl.c1 - pfx) + hs; + pane.cur_row = row1; + pane.cur_col = col1; + pane.cur_off = 0; + pane.cur_pinned = true; + pane.msel.active = false; + pane.pending = 0; + if (!pane.isTerminal()) pane.mode = .normal; + pane.vsel = .{ .active = row0 != row1 or col0 != col1, .row = row0, .col = col0, .explicit = false }; + } + if (pane.mode == .tty) return; + if (cut) { + if (pane.vsel.active) p.normalDelete(pane, true); + } else if (pane.vsel.active) { + p.normalReplaceYank(pane); + } else if (pane.file) |*f| { + // bare cursor: splice the register in literally (no linewise + // magic) so a paste right after a cut restores the text exactly + const y = p.yank orelse return; + if (y.len == 0) return; + const at = modal.Cursor{ .row = @intCast(@max(0, pane.cur_row)), .col = @intCast(@max(0, pane.cur_col)) }; + p.pushUndo(pane); + const new = modal.insertAt(p.gpa, f.content, at, y) catch return; + p.setFileContent(f, new); + pane.vsel = .{ .active = y.len > 1, .row = @intCast(at.row), .col = @intCast(at.col), .explicit = false }; + const end = modal.advanceBy(at, y); + if (end.col > 0) { + pane.cur_row = @intCast(end.row); + pane.cur_col = @intCast(end.col - 1); + } else { + // the register ended in '\n': the cursor lands ON that newline + pane.cur_row = @intCast(end.row -| 1); + pane.cur_col = @intCast(modal.lineSlice(f.content, end.row -| 1).len); + } + pane.cur_off = 0; + pane.cur_pinned = true; + pane.sticky_col = -1; + pane.ensureCursorVisible(); + } else p.normalPaste(pane, true); // terminal: splice run text at the cursor + } + /// tty mode: encode the key the way a terminal would and send it to the pty. fn forwardKey(p: *Pardes, id: usize, key: Key) void { var cbuf: [1]u8 = undefined; -- cgit v1.3