Skip to content

Commit

Permalink
StyledDocument clamp getAbsolutePosition return value
Browse files Browse the repository at this point in the history
  • Loading branch information
Jugen committed Jul 24, 2024
1 parent 323de89 commit b16bcc8
Showing 1 changed file with 2 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,7 @@ default StyleSpans<S> getStyleSpans(int paragraph, int from, int to) {
*/
default int getAbsolutePosition(int paragraphIndex, int columnPosition) {
int position = position(paragraphIndex, columnPosition).toOffset();
if (position < 0) {
throw new IndexOutOfBoundsException(String.format("Negative index! Out of bounds by %s.", 0 - position));
}
if (length() < position) {
throw new IndexOutOfBoundsException(String.format("Out of bounds by %s. Area Length: %s", position - length(), length()));
}
return position;
if (position > 0) return Math.min(position, length());
return 0;
}
}

0 comments on commit b16bcc8

Please sign in to comment.