mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-65641
This commit is contained in:
@@ -307,9 +307,31 @@ public class LivePreview extends DocumentAdapter implements ReplacementView.Dele
|
||||
|
||||
private void highlightUsages(TextRange oldCursorRange) {
|
||||
if (myEditor == null || myShouldStop) return;
|
||||
LiveOccurrence firstVisibleOccurrence = null;
|
||||
LiveOccurrence firstOccurrence = null;
|
||||
for (LiveOccurrence o : mySearchResults) {
|
||||
for (TextRange textRange : o.getSecondaryRanges()) {
|
||||
highlightRange(textRange, OTHER_TARGETS_ATTRIBUTES, myHighlighters);
|
||||
}
|
||||
highlightRange(o.getPrimaryRange(), MAIN_TARGET_ATTRIBUTES, myHighlighters);
|
||||
}
|
||||
|
||||
if (!tryToRepairOldCursor(oldCursorRange)) {
|
||||
LiveOccurrence afterCaret = firstOccurrenceAfterCaret();
|
||||
if (afterCaret != null) {
|
||||
setCursor(afterCaret);
|
||||
} else {
|
||||
LiveOccurrence occurrence = firstVisibleOccurrence();
|
||||
if (occurrence != null) {
|
||||
setCursor(occurrence);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private LiveOccurrence firstVisibleOccurrence() {
|
||||
int offset = Integer.MAX_VALUE;
|
||||
LiveOccurrence firstOccurrence = null;
|
||||
LiveOccurrence firstVisibleOccurrence = null;
|
||||
for (LiveOccurrence o : mySearchResults) {
|
||||
if (insideVisibleArea(myEditor, o.getPrimaryRange())) {
|
||||
if (firstVisibleOccurrence == null || o.getPrimaryRange().getStartOffset() < firstVisibleOccurrence.getPrimaryRange().getStartOffset()) {
|
||||
@@ -320,16 +342,22 @@ public class LivePreview extends DocumentAdapter implements ReplacementView.Dele
|
||||
offset = o.getPrimaryRange().getStartOffset();
|
||||
firstOccurrence = o;
|
||||
}
|
||||
}
|
||||
return firstVisibleOccurrence != null ? firstVisibleOccurrence : firstOccurrence;
|
||||
}
|
||||
|
||||
for (TextRange textRange : o.getSecondaryRanges()) {
|
||||
highlightRange(textRange, OTHER_TARGETS_ATTRIBUTES, myHighlighters);
|
||||
@Nullable
|
||||
private LiveOccurrence firstOccurrenceAfterCaret() {
|
||||
LiveOccurrence afterCaret = null;
|
||||
int caret = myEditor.getCaretModel().getOffset();
|
||||
for (LiveOccurrence occurrence : mySearchResults) {
|
||||
if (occurrence.getPrimaryRange().getStartOffset() >= caret) {
|
||||
if (afterCaret == null || occurrence.getPrimaryRange().getStartOffset() < afterCaret.getPrimaryRange().getStartOffset() ) {
|
||||
afterCaret = occurrence;
|
||||
}
|
||||
}
|
||||
highlightRange(o.getPrimaryRange(), MAIN_TARGET_ATTRIBUTES, myHighlighters);
|
||||
}
|
||||
|
||||
if (!tryToRepairOldCursor(oldCursorRange)) {
|
||||
setCursor(firstVisibleOccurrence != null ? firstVisibleOccurrence : firstOccurrence);
|
||||
}
|
||||
return afterCaret;
|
||||
}
|
||||
|
||||
private boolean tryToRepairOldCursor(TextRange oldCursorRange) {
|
||||
|
||||
Reference in New Issue
Block a user