Skip to content

Commit fe682ae

Browse files
committed
Fix inserting wide char into column previously occupied by normal-width char
Since an East Asian wide character takes two screen columns, if we're inserting one into a spot previously occupied by a normal-width character, we need to overwrite the contents of the column to the right of the position into which the character is inserted. We do this shifting the contents of the rest of the line left in the array, then updating our idea of the storage used -- or at least that's what's supposed to happen. There are at least two problems with the current implementation: (1) findStartOfColumn() is used in a few places to get the spot in the array where a column starts, but this relies on the offset array, which is potentially out of date at this point. Fix this by adding the shift (which will be used to update the offset array later) to the value whenever we use findStartOfColumn(). (2) When truncating the line by reducing the storage used count, we currently effectively reduce the count by the size of the last column in the line, which is not necessarily the same as the size of the overwritten column. We should instead adjust by the size of the just-overwritten column (which is readily available to us at this point). Fixes #145, and potentially a class of other difficult-to-reproduce bugs involving East Asian wide character support.
1 parent 389f117 commit fe682ae

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

libraries/emulatorview/src/jackpal/androidterm/emulatorview/UnicodeTranscript.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ public void setChar(int column, int codePoint) {
964964
int nextWidth = UnicodeTranscript.charWidth(text, nextPos);
965965
int nextLen;
966966
if (column + nextWidth + 1 < columns) {
967-
nextLen = findStartOfColumn(column + nextWidth + 1) - nextPos;
967+
nextLen = findStartOfColumn(column + nextWidth + 1) + shift - nextPos;
968968
} else {
969969
nextLen = spaceUsed - nextPos;
970970
}
@@ -983,7 +983,7 @@ public void setChar(int column, int codePoint) {
983983
shift -= nextLen;
984984

985985
// Truncate the line
986-
offset[0] = (short) findStartOfColumn(columns - 1);
986+
offset[0] -= nextLen;
987987
}
988988

989989
// Correct the offset for the next column to reflect width change

0 commit comments

Comments
 (0)