mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
EA-87991 EA-87365 diff: do not access Document outside of valid ranges
This commit is contained in:
@@ -60,9 +60,16 @@ public class LineCol {
|
||||
|
||||
@NotNull
|
||||
public static LineCol fromOffset(@NotNull Document document, int offset) {
|
||||
int line = document.getLineNumber(offset);
|
||||
int column = offset - document.getLineStartOffset(line);
|
||||
return new LineCol(line, column);
|
||||
if (offset < document.getTextLength()) {
|
||||
int line = document.getLineNumber(offset);
|
||||
int column = offset - document.getLineStartOffset(line);
|
||||
return new LineCol(line, column);
|
||||
}
|
||||
else {
|
||||
int line = Math.max(0, document.getLineCount() - 1);
|
||||
int column = document.getLineEndOffset(line) - document.getLineStartOffset(line);
|
||||
return new LineCol(line, column);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -79,7 +86,8 @@ public class LineCol {
|
||||
}
|
||||
|
||||
public int toOffset(@NotNull Document document) {
|
||||
return document.getLineStartOffset(line) + column;
|
||||
if (line >= document.getLineCount()) return document.getTextLength();
|
||||
return Math.min(document.getLineStartOffset(line) + column, document.getLineEndOffset(line));
|
||||
}
|
||||
|
||||
public int toOffset(@NotNull Editor editor) {
|
||||
|
||||
Reference in New Issue
Block a user