mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-06 02:35:19 +08:00
Fix crash with wide character in last column
Ignore wide character outputs instead of crashing when the cursor is in the last column with autowrap disabled.
This commit is contained in:
@@ -2156,15 +2156,22 @@ public final class TerminalEmulator {
|
||||
|
||||
final boolean autoWrap = isDecsetInternalBitSet(DECSET_BIT_AUTOWRAP);
|
||||
final int displayWidth = WcWidth.width(codePoint);
|
||||
final boolean cursorInLastColumn = mCursorCol == mRightMargin - 1;
|
||||
|
||||
if (autoWrap && (mCursorCol == mRightMargin - 1 && ((mAboutToAutoWrap && displayWidth == 1) || displayWidth == 2))) {
|
||||
mScreen.setLineWrap(mCursorRow);
|
||||
mCursorCol = mLeftMargin;
|
||||
if (mCursorRow + 1 < mBottomMargin) {
|
||||
mCursorRow++;
|
||||
} else {
|
||||
scrollDownOneLine();
|
||||
if (autoWrap) {
|
||||
if (cursorInLastColumn && ((mAboutToAutoWrap && displayWidth == 1) || displayWidth == 2)) {
|
||||
mScreen.setLineWrap(mCursorRow);
|
||||
mCursorCol = mLeftMargin;
|
||||
if (mCursorRow + 1 < mBottomMargin) {
|
||||
mCursorRow++;
|
||||
} else {
|
||||
scrollDownOneLine();
|
||||
}
|
||||
}
|
||||
} else if (cursorInLastColumn && displayWidth == 2) {
|
||||
// The behaviour when a wide character is output with cursor in the last column when
|
||||
// autowrap is disabled is not obvious - it's ignored here.
|
||||
return;
|
||||
}
|
||||
|
||||
if (mInsertMode && displayWidth > 0) {
|
||||
|
@@ -84,4 +84,12 @@ public class UnicodeInputTest extends TerminalTestCase {
|
||||
assertLineIs(0, "\uFFFDY ");
|
||||
}
|
||||
|
||||
public void testWideCharacterWithoutWrapping() throws Exception {
|
||||
// With wraparound disabled. The behaviour when a wide character is output with cursor in
|
||||
// the last column when autowrap is disabled is not obvious, but we expect the wide
|
||||
// character to be ignored here.
|
||||
withTerminalSized(3, 3).enterString("\033[?7l").enterString("枝枝枝").assertLinesAre("枝 ", " ", " ");
|
||||
enterString("a枝").assertLinesAre("枝a", " ", " ");
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user