Skip to content

Fix relative cursor moves, CHA and HPA in origin mode - #6197

Open
matthematics1137 wants to merge 1 commit into
xtermjs:masterfrom
matthematics1137:fix-origin-mode-relative-cursor-movement
Open

matthematics1137 wants to merge 1 commit into
xtermjs:masterfrom
matthematics1137:fix-origin-mode-relative-cursor-movement

Conversation

@matthematics1137

Copy link
Copy Markdown

With origin mode (DECOM, CSI ? 6 h) on and a top margin below the first
row, every relative cursor move also pushes the cursor down, usually to the
bottom margin. This affects CUU, CUD, CUF, CUB, CNL, CPL, HPR and VPR, and
also CHA and HPA.

To reproduce:

printf '\033[2J\033[3;6r\033[?6h\033[2;3H\033[2CX\033[?6l\033[r\033[8;1H'

X should be on row 4, column 5. CUF only moves right. xterm and tmux put it
there. xterm.js puts it on row 6, the bottom margin.

The cause: _setCursor(x, y) takes y relative to the scroll top in origin
mode and adds scrollTop itself. But _moveCursor passes
this._activeBuffer.y + y, and CHA/HPA pass this._activeBuffer.y. Both are
absolute rows, so scrollTop is added a second time. CUP and VPA pass
relative rows, so they were not affected.

The fix: _moveCursor, CHA and HPA pass the cursor row relative to the scroll
top in origin mode, through a small _getCursorRow() helper. Outside origin
mode nothing changes.

Test: cursor positioning > relative cursor moves, CHA and HPA with DECOM and scroll margins in InputHandler.test.ts. It fails on master: CUF leaves
the cursor at [4, 5] instead of [4, 3].

Checked locally:

  • npm run test-unit: 2408 passing.
  • npm run lint-changes: clean.
  • tsc -p src/common: clean.

With origin mode (DECOM) on, `_setCursor` takes a row relative to the
scroll top, but `_moveCursor` (CUU, CUD, CUF, CUB, CNL, CPL, HPR, VPR) and
CHA/HPA passed it the absolute cursor row. The scroll top was added a
second time, so with a top margin every one of these moves also pushed
the cursor down, usually to the bottom margin: `CSI 3;6 r`, `CSI ? 6 h`,
`CSI 2;3 H`, `CSI 2 C` left the cursor on row 6 instead of row 4.

Pass the cursor row relative to the scroll top in origin mode.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant