diff --git a/terminal-emulator/src/main/java/com/termux/terminal/TerminalEmulator.java b/terminal-emulator/src/main/java/com/termux/terminal/TerminalEmulator.java index f778cf9240..3d9d7c8c79 100644 --- a/terminal-emulator/src/main/java/com/termux/terminal/TerminalEmulator.java +++ b/terminal-emulator/src/main/java/com/termux/terminal/TerminalEmulator.java @@ -1376,10 +1376,10 @@ private void doCsi(int b) { } break; case 'A': // "CSI${n}A" - Cursor up (CUU) ${n} rows. - setCursorRow(Math.max(mTopMargin, mCursorRow - getArg0(1))); + setCursorRow(Math.max(0, mCursorRow - getArg0(1))); break; case 'B': // "CSI${n}B" - Cursor down (CUD) ${n} rows. - setCursorRow(Math.min(mBottomMargin - 1, mCursorRow + getArg0(1))); + setCursorRow(Math.min(mRows - 1, mCursorRow + getArg0(1))); break; case 'C': // "CSI${n}C" - Cursor forward (CUF). case 'a': // "CSI${n}a" - Horizontal position relative (HPR). From ISO-6428/ECMA-48. diff --git a/terminal-emulator/src/test/java/com/termux/terminal/ScrollRegionTest.java b/terminal-emulator/src/test/java/com/termux/terminal/ScrollRegionTest.java index 260a481a69..bbb5e7ac73 100644 --- a/terminal-emulator/src/test/java/com/termux/terminal/ScrollRegionTest.java +++ b/terminal-emulator/src/test/java/com/termux/terminal/ScrollRegionTest.java @@ -107,4 +107,24 @@ public void testScrollDownBelowScrollRegion() { assertLinesAre("1 ", "2 ", "3 ", "QQ", "YY"); } + /** See https://github.com/termux/termux-app/issues/1340 */ + public void testScrollRegionDoesNotLimitCursorMovement() { + withTerminalSized(6, 4) + .enterString("\033[4;7r\033[3;1Haaa\033[Axxx") + .assertLinesAre( + " ", + " xxx", + "aaa ", + " " + ); + + withTerminalSized(6, 4) + .enterString("\033[1;3r\033[3;1Haaa\033[Bxxx") + .assertLinesAre( + " ", + " ", + "aaa ", + " xxx" + ); + } }