EmulatorView: don't crash when link ends on the last column in a line
When linkifying, endRow/endCol currently represent the screen position immediately after the last character in the link; this fits naturally with Java subsequence APIs (where the end index is always one after the last position in the subsequence), but results in endRow being too large if the link in question ends on the last column of a line. Instead, have endRow/endCol point to the last character of the link, avoiding this problem (and fixing an off-by-one error in the FullUnicodeLine case, where we were already calculating endRow/endCol this way). Fixes #341.
This commit is contained in:
parent
46062fcb1e
commit
5cf4396d5d
@ -358,11 +358,14 @@ public class EmulatorView extends View implements GestureDetector.OnGestureListe
|
||||
int endRow;
|
||||
int endCol;
|
||||
if (textIsBasic) {
|
||||
/* endRow/endCol must be the last character of the link,
|
||||
* not one after -- otherwise endRow might be too large */
|
||||
int spanLastPos = spanEnd - 1;
|
||||
// Basic line -- can assume one char per column
|
||||
startRow = spanStart / mColumns;
|
||||
startCol = spanStart % mColumns;
|
||||
endRow = spanEnd / mColumns;
|
||||
endCol = spanEnd % mColumns;
|
||||
endRow = spanLastPos / mColumns;
|
||||
endCol = spanLastPos % mColumns;
|
||||
} else {
|
||||
/* Iterate over the line to get starting and ending columns
|
||||
* for this span */
|
||||
@ -403,9 +406,9 @@ public class EmulatorView extends View implements GestureDetector.OnGestureListe
|
||||
for(int i=startRow; i <= endRow; ++i)
|
||||
{
|
||||
int runStart = (i == startRow) ? startCol: 0;
|
||||
int runEnd = (i == endRow) ? endCol : mColumns;
|
||||
int runEnd = (i == endRow) ? endCol : mColumns - 1;
|
||||
|
||||
Arrays.fill(linkRows[i], runStart, runEnd, url);
|
||||
Arrays.fill(linkRows[i], runStart, runEnd + 1, url);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user