Fix relative cursor moves, CHA and HPA in origin mode - #6197
Open
matthematics1137 wants to merge 1 commit into
Open
matthematics1137 wants to merge 1 commit into
matthematics1137 wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With origin mode (DECOM,
CSI ? 6 h) on and a top margin below the firstrow, 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:
Xshould be on row 4, column 5. CUF only moves right. xterm and tmux put itthere. xterm.js puts it on row 6, the bottom margin.
The cause:
_setCursor(x, y)takesyrelative to the scroll top in originmode and adds
scrollTopitself. But_moveCursorpassesthis._activeBuffer.y + y, and CHA/HPA passthis._activeBuffer.y. Both areabsolute rows, so
scrollTopis added a second time. CUP and VPA passrelative rows, so they were not affected.
The fix:
_moveCursor, CHA and HPA pass the cursor row relative to the scrolltop in origin mode, through a small
_getCursorRow()helper. Outside originmode nothing changes.
Test:
cursor positioning > relative cursor moves, CHA and HPA with DECOM and scroll marginsinInputHandler.test.ts. It fails onmaster:CUFleavesthe 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.