szn

Bug 558 — Command and action handler bugs across cmd.zig, server.zig, choose.zig, and buffer.zig

558. Missing resizes, dropped combining marks, unguarded session rollback, and rejected keybinding flags

Severity: HIGH
Status: ✅ RESOLVED
Files: src/server/server.zig:1110-1114, src/cmd/cmd.zig:51-74, src/cmd/cmd.zig:102-124, src/cmd/cmd.zig:185-374, src/cmd/cmd.zig:541-550, src/cmd/cmd.zig:780-801, src/choose.zig:80-110, src/buffer.zig:39-55

Problem

  1. Server.executeAction(.rotate_window) omits w.resize(w.width, w.height) (src/server/server.zig:1110-1114): cmdRotateWindow (src/cmd/cmd.zig:385-386) calls window.layout.rotatePanes() followed by window.resize(window.width, window.height), whereas .rotate_window in Server.executeAction (Ctrl-B Ctrl-O) only calls w.layout.rotatePanes(), leaving rotated panes with stale grid and PTY dimensions when panes have unequal sizes.

  2. cmdSwapPane omits pane resize, border cache invalidation, server.dirty = true, and -U/-D (src/cmd/cmd.zig:337-374): Unlike Server.swapPaneRelative (src/server/server.zig:1409-1434), cmdSwapPane swaps the two leaf pointers in window.layout without calling window.resizePaneToNode(n1) / window.resizePaneToNode(n2), without calling window.invalidateBorderFormat(), and without setting server.dirty = true. It also rejects -U and -D (return .err), even though key_binding.zig:762-763 maps .swap_pane_up to "swap-pane -U" and .swap_pane_down to "swap-pane -D".

  3. cmdSelectWindow, cmdSelectPane, and cmdSplitWindow reject flags emitted by key_binding.zig (src/cmd/cmd.zig:185-326): key_binding.zig:736-780 formats "select-window -t 0", "select-pane -U/-D/-L/-R", and "split-window -h -p 50". If a list-keys dump is re-sourced or a user binds those commands via :bind-key, cmdSelectWindow rejects -t, cmdSelectPane rejects -U/-D/-L/-R, and cmdSplitWindow rejects -p.

  4. cmdCapturePane drops combining characters (comb1/comb2) and sixel checks (src/cmd/cmd.zig:780-801): cmdCapturePane only encodes cell.char and ignores cell.comb1 and cell.comb2 (via grid.combiningCodepoint), stripping all Thai vowels/tone marks and Unicode combining accents from capture-pane output. It also does not check cell.attr.sixel (where cell.char is a sixel image ID rather than a character).

  5. cmdPasteBuffer ignores bracketed paste mode (src/cmd/cmd.zig:541-550): Server.pasteActiveBuffer (src/server/server.zig:1449-1461) wraps pasted bytes in \x1b[200~ .. \x1b[201~ when pane.screen.mode.paste is true, whereas cmdPasteBuffer writes raw buf.data directly to the PTY without bracketed paste markers.

  6. cmdSwitchClient does not mark the server dirty or recalculate minimum size (src/cmd/cmd.zig:102-124): Swaps server.sessions.items[0] and server.sessions.items[target_idx] without setting server.dirty = true, server.status_dirty = true, or calling server.recalculateMinimumSize().

  7. cmdNewSession allows duplicate session names and its error rollback kills the existing session (src/cmd/cmd.zig:51-74): cmdNewSession does not check if a session named name already exists. If server.setupPane fails at line 63, server.killSession(session.name) searches server.sessions from index 0 by name and destroys the pre-existing session with that name while leaving the half-created session in server.sessions! Additionally, createSession hardcodes 80x24 without calling server.recalculateMinimumSize() for already-attached clients.

  8. ChooseMode.renderIntoGrid ignores character display width and grid bounds (src/choose.zig:80-110): Advances col += 1 per UTF-8 codepoint without checking char_width.charWidth(cp) (so zero-width combining marks and width-2 CJK characters misalign the row) and without checking if (col >= grid.width) break;.

  9. BufferList.push / pushOwned allows duplicate buffer names (src/buffer.zig:39-55): Running set-buffer -b foo "1" followed by set-buffer -b foo "2" inserts a second "foo" entry instead of replacing the existing "foo" buffer.

Proposed Fix

  1. Call w.resize(w.width, w.height) in Server.executeAction(.rotate_window).
  2. Route cmdSwapPane and Server.swapPaneRelative through a single helper that supports -U/-D and calls resizePaneToNode, invalidateBorderFormat, and server.dirty = true.
  3. Support -t <idx> in cmdSelectWindow, -L/-R/-U/-D in cmdSelectPane, and -p <pct> / -l <size> in cmdSplitWindow.
  4. In cmdCapturePane, treat cell.attr.sixel as ' ' and append grid.combiningCodepoint(cell.comb1) / grid.combiningCodepoint(cell.comb2) after the base character.
  5. Respect pane.screen.mode.paste in cmdPasteBuffer.
  6. Set server.dirty = true, server.status_dirty = true, and server.recalculateMinimumSize() in cmdSwitchClient and cmdNewSession, and reject duplicate session names in cmdNewSession before createSession.
  7. Check char_width.charWidth(cp) and col < grid.width in ChooseMode.renderIntoGrid, and replace existing buffers with the same name in BufferList.pushOwned.