szn

Bug 565 — Mouse drag-to-resize fires without a split / on outer edges and leaves stale mouse_resize_pane pointers

565. Border-drag resize arms on single-pane and outer window edges, shrinks terminals below their layout slot, and omits #283 stale-pointer cleanup

Severity: HIGH (corrupted pane geometry on ordinary mouse drags + dangling pointer on mid-drag pane destruction)
Status: ✅ RESOLVED (rev 849:33bd56b0a6aa)
Files:

Related: Bug #283, Bug #511, Bug Index

Symptom

  1. Single-pane shrink and spurious SIGWINCH: Clicking within 2 cells of the right or bottom edge of a single-pane window (for example, starting a text selection near the right margin) armed border drag-to-resize. Dragging leftward or upward shrank the pane’s terminal grid inside its unchanged layout slot and sent SIGWINCH to the running application, leaving blank space outside the shrunk grid1.
  2. Outer-edge misfire in split windows: Clicking near the outer right edge of the rightmost pane (or outer bottom edge of the bottommost pane) in a split window armed a border drag even though no divider existed on that edge1.
  3. Stale pointer hazard on mid-drag teardown: If the pane being dragged exited (destroyPane) or its session was killed (killSession / killAllSessions) before mouse release, Server.mouse_resize_pane was not cleared. If a newly allocated Pane reused the same address, isPaneValid would pass and drag events would resize the wrong pane1.

Cause

Mouse drag-to-resize (introduced in rev 836:872ab1375c72) had three interacting defects across src/server/server.zig1:

Defect Location (Before Fix) Mechanism
Unconditional border arming Server.processInput (left-press branch) Checked only m.x >= right_edge -| 2 / m.y >= bottom_edge -| 2 with no check that a split existed on that axis or that the edge was strictly inside window.layout.width / window.layout.height.
Single-pane resizeTerminal fallback Server.processInput (left-drag branch) Called resizePaneBy(window, rp, dw, dh). When Layout.resizePane returned false (no matching split), resizePaneBy fell back to pane.resizeTerminal(tw, th) (kept for explicit CLI resize-pane -x/-y in Bug #511), shrinking the terminal under its layout rectangle.
Missing #283 pointer cleanup clearPaneMouseRefs & clearPaneMouseRefsBulk Cleared mouse_press_pane and mouse_autoscroll_pane, but omitted the newly added mouse_resize_pane and mouse_resize_axis fields (the exact bug class tracked in Bug #283).

Fix

Implemented in rev 849:33bd56b0a6aa:

  1. Axis split predicate on Layout (src/layout.zig:303-319)2: Added Layout.hasSplitOnAxis(self, target, dir) to check whether target has at least one ancestor split matching .horizontal or .vertical.
  2. Interior-divider arming gate (src/server/server.zig:2327-2348)1: Gated right-edge and bottom-edge arming on both strict interior bounds and an existing split on the dragged axis:
    const has_right_split = right_edge < window.layout.width and
        window.layout.hasSplitOnAxis(pp, .horizontal);
    const has_bottom_split = bottom_edge < window.layout.height and
        window.layout.hasSplitOnAxis(pp, .vertical);
    
  3. Layout-only drag resize without fallback (src/server/server.zig:2239-2266)1: Replaced the resizePaneBy call in the drag handler with a direct window.layout.resizePane(rp, dw, dh) followed by window.resize(window.width, window.height), never falling back to pane.resizeTerminal. When !self.isPaneValid(rp), the handler now also resets mouse_resize_pane and mouse_resize_axis to null.
  4. Teardown cleanup (#283 parity) (src/server/server.zig:909-920, src/server/server.zig:3852-3858)1: Cleared mouse_resize_pane and mouse_resize_axis in both clearPaneMouseRefs(pane) (called by destroyPane) and clearPaneMouseRefsBulk() (called by killSession / killAllSessions).

Verification

  1. Source: src/server/server.zig (Server.clearPaneMouseRefs, Server.processInput, Server.clearPaneMouseRefsBulk, and mouse drag-resize / #283 tests). ↩ ↩2 ↩3 ↩4 ↩5 ↩6 ↩7

  2. Source: src/layout.zig (Layout.hasSplitOnAxis, Layout.hasSplitOnAxisNode, and Layout.resizePane). ↩