szn

Bug 427 — Mouse wheel in Alternate Screen forces copy-mode on empty/stale scrollback instead of forwarding arrow keys

427. Mouse wheel in Alternate Screen forces copy-mode on empty/stale scrollback instead of forwarding arrow keys

Severity: MEDIUM Status: ✅ RESOLVED

When mouse tracking is enabled (mouse = on), mouse wheel events (.scroll_up and .scroll_down) on an active pane that does not claim raw SGR mouse reporting (wants_mouse == false) unconditionally enter szn’s copy-mode:

// src/server/server.zig:1894-1905
} else {
    handled = true;
    if (m.button == .scroll_up) {
        if (active_pane.screen.copy_mode) |*target_cm| {
            target_cm.scroll_offset = @min(target_cm.scroll_offset + 3, @as(u32, @intCast(active_pane.screen.grid.historyLen())));
        } else {
            active_pane.enterCopyMode() catch |err| std.log.warn("enterCopyMode failed: {any}", .{err});
            if (active_pane.screen.copy_mode) |*target_cm| {
                target_cm.scroll_offset = @min(3, @as(u32, @intCast(active_pane.screen.grid.historyLen())));
            }
            self.dirty = true;
        }
        active_pane.dirty = true;
    }
}

Problem & Impact

When running an interactive CLI or full-screen TUI tool (antigravity-cli, opencode, vim, less, man, nano) that runs in the Alternate Screen (ESC [ ? 1049 h / mode.alt_screen == true):

  1. Empty/Stale History in Copy-Mode: In the alternate screen buffer, the terminal scrollback history is empty (historyLen() == 0). Scrolling the wheel enters copy-mode with zero history or reveals stale text from before the program was launched.
  2. Keyboard Interception: Copy-mode hijacks all subsequent keystrokes (such as typing prompts or navigating), wedging the user in copy-mode until q or Enter is explicitly pressed.
  3. Application Cannot Scroll: The running application never receives the scroll intent, preventing tools with their own internal viewport (such as agent conversation history) from scrolling.

Reference Behavior (tmux)

In standard tmux, the default mouse wheel binding (WheelUpPane / WheelDownPane) inspects whether the alternate screen is active via #{alternate_on}:

Proposed Fix

In src/server/server.zig:1894, check active_pane.screen.mode.alt_screen: