diff options
Diffstat (limited to 'core/mouse.zig')
| -rw-r--r-- | core/mouse.zig | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/core/mouse.zig b/core/mouse.zig index 3d7c5af9..1882b691 100644 --- a/core/mouse.zig +++ b/core/mouse.zig @@ -184,7 +184,7 @@ fn programWheel(p: *Pardes, id: usize, m: Mouse, col: u16, row: u16) bool { .wheel_left => .wheel_left, else => .wheel_right, }; - const bytes = panes.Term.wheel(pane.terminal.?, &buf, wheel, gcol, grow, .{ .alt = m.alt, .ctrl = m.ctrl }) orelse return true; + const bytes = panes.Term.wheel(pane.terminal.?, &pane.term_mouse, &buf, wheel, gcol, grow, .{ .alt = m.alt, .ctrl = m.ctrl }) orelse return true; for (0..@intCast(config.wheel_rows)) |_| p.emitWrite(id, bytes); return true; } @@ -247,8 +247,11 @@ fn kindMouse(p: *Pardes, m: Mouse) bool { if (m.kind == .press) v.active = id; if (m.kind == .press and m.button != .wheel_up and m.button != .wheel_down and m.button != .wheel_left and m.button != .wheel_right) v.kind_grab = @intCast(id); if (m.kind == .release) v.kind_grab = null; - const col = std.math.clamp(m.col, x0, r.x + r.w -| 1) - x0; - const row = std.math.clamp(m.row, top, r.y + r.h -| 1) - top; + // Grabbed, it may be anywhere, and the pane since made too narrow + // or short for a cell of body (a resize, a pane added above): its + // body's last cell, the first of none. + const col = @min(m.col -| x0, (r.x + r.w) -| x0 -| 1); + const row = @min(m.row -| top, (r.y + r.h) -| top -| 1); return pardes.Kind.mouse(p, id, m, col, row); } kindLeave(p); @@ -298,7 +301,7 @@ fn programMouse(p: *Pardes, m: Mouse) bool { }; if (m.kind == .press) grab.held |= bit; if (m.kind == .release) grab.held &= ~bit; - const bytes = panes.Term.mouse(pane.terminal.?, &buf, action, button, mods, col, row, grab.held != 0); + const bytes = panes.Term.mouse(pane.terminal.?, &pane.term_mouse, &buf, action, button, mods, col, row, grab.held != 0); if (bytes.len > 0) p.emitWrite(grab.id, bytes); if (grab.held == 0) v.mouse_grab = null; return true; @@ -322,7 +325,7 @@ fn programMouse(p: *Pardes, m: Mouse) bool { pane.focus = .body; pane.closePrompt(); v.mouse_grab = .{ .id = id, .serial = pane.serial, .held = bit, .unshift = shifted_to_program }; - const bytes = panes.Term.mouse(pane.terminal.?, &buf, .press, button, mods, cell.col, cell.row, true); + const bytes = panes.Term.mouse(pane.terminal.?, &pane.term_mouse, &buf, .press, button, mods, cell.col, cell.row, true); if (bytes.len > 0) p.emitWrite(id, bytes); return true; }, @@ -330,7 +333,7 @@ fn programMouse(p: *Pardes, m: Mouse) bool { // pardes's. .release, .drag => return false, .motion => { - const bytes = panes.Term.mouse(pane.terminal.?, &buf, .motion, null, mods, cell.col, cell.row, false); + const bytes = panes.Term.mouse(pane.terminal.?, &pane.term_mouse, &buf, .motion, null, mods, cell.col, cell.row, false); if (bytes.len > 0) p.emitWrite(id, bytes); // Under 1003 the move is the program's; below that pardes // hovers as ever. @@ -432,7 +435,7 @@ fn chordCutPaste(p: *Pardes, cut: bool) edit.Error!void { const row = @max(0, pane.sel[sel_slot].r1 - @as(i32, pane.tag_rows)); var mb: [64]u8 = undefined; for ([_]panes.Term.MouseAction{ .press, .release }) |action| { - const bytes = panes.Term.mouse(pane.terminal.?, &mb, action, .left, .{}, col, row, action == .press); + const bytes = panes.Term.mouse(pane.terminal.?, &pane.term_mouse, &mb, action, .left, .{}, col, row, action == .press); if (bytes.len > 0) p.emitWrite(s.id, bytes); } } @@ -1497,7 +1500,7 @@ test "mouse thumb buttons navigate once and clear selection gestures" { } test "a chorded exec an event reader holds is told with its argument, and written back runs with it" { - const th = @import("ninep/testing.zig"); + const th = @import("ninep/harness.zig"); const p = try th.withFile(std.testing.allocator, "Msg said\narg-text\n"); defer p.deinit(); const serial = p.panes[0].?.serial; |
