Skip to content

Commit cdccc2c

Browse files
committed
Do not limit cursor movement to scroll region
The scrolling region set by DECSTBM should not affect the Cursor Down (CUD) and Cursor Up (CUU) escape sequences. Fixes #1340.
1 parent 070436a commit cdccc2c

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

terminal-emulator/src/main/java/com/termux/terminal/TerminalEmulator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,10 +1376,10 @@ private void doCsi(int b) {
13761376
}
13771377
break;
13781378
case 'A': // "CSI${n}A" - Cursor up (CUU) ${n} rows.
1379-
setCursorRow(Math.max(mTopMargin, mCursorRow - getArg0(1)));
1379+
setCursorRow(Math.max(0, mCursorRow - getArg0(1)));
13801380
break;
13811381
case 'B': // "CSI${n}B" - Cursor down (CUD) ${n} rows.
1382-
setCursorRow(Math.min(mBottomMargin - 1, mCursorRow + getArg0(1)));
1382+
setCursorRow(Math.min(mRows - 1, mCursorRow + getArg0(1)));
13831383
break;
13841384
case 'C': // "CSI${n}C" - Cursor forward (CUF).
13851385
case 'a': // "CSI${n}a" - Horizontal position relative (HPR). From ISO-6428/ECMA-48.

terminal-emulator/src/test/java/com/termux/terminal/ScrollRegionTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,24 @@ public void testScrollDownBelowScrollRegion() {
107107
assertLinesAre("1 ", "2 ", "3 ", "QQ", "YY");
108108
}
109109

110+
/** See https://github.com/termux/termux-app/issues/1340 */
111+
public void testScrollRegionDoesNotLimitCursorMovement() {
112+
withTerminalSized(6, 4)
113+
.enterString("\033[4;7r\033[3;1Haaa\033[Axxx")
114+
.assertLinesAre(
115+
" ",
116+
" xxx",
117+
"aaa ",
118+
" "
119+
);
120+
121+
withTerminalSized(6, 4)
122+
.enterString("\033[1;3r\033[3;1Haaa\033[Bxxx")
123+
.assertLinesAre(
124+
" ",
125+
" ",
126+
"aaa ",
127+
" xxx"
128+
);
129+
}
110130
}

0 commit comments

Comments
 (0)