use of com.intellij.find.FindResult in project intellij-community by JetBrains.
the class SearchResults method prevOccurrence.
public void prevOccurrence(boolean findSelected) {
if (findSelected) {
if (mySelectionManager.removeCurrentSelection()) {
myCursor = firstOccurrenceAtOrAfterCaret();
} else {
myCursor = null;
}
notifyCursorMoved();
} else {
FindResult next = null;
if (myFindModel == null)
return;
boolean processFromTheBeginning = false;
if (myNotFoundState) {
myNotFoundState = false;
processFromTheBeginning = true;
}
if (!myFindModel.isGlobal()) {
if (myCursor != null) {
next = prevOccurrence(myCursor);
}
} else {
next = firstOccurrenceBeforeCaret();
}
if (next == null) {
if (processFromTheBeginning) {
if (hasMatches()) {
next = getOccurrences().get(getOccurrences().size() - 1);
}
} else {
setNotFoundState(false);
}
}
moveCursorTo(next, false);
}
push();
}
use of com.intellij.find.FindResult in project intellij-community by JetBrains.
the class SearchResults method firstOccurrenceAtOrAfterCaret.
@Nullable
private FindResult firstOccurrenceAtOrAfterCaret() {
int offset = getEditor().getCaretModel().getOffset();
for (FindResult occurrence : myOccurrences) {
if (offset <= occurrence.getEndOffset() && offset >= occurrence.getStartOffset()) {
return occurrence;
}
}
int selectionStartOffset = getEditor().getSelectionModel().getSelectionStart();
int selectionEndOffset = getEditor().getSelectionModel().getSelectionEnd();
for (FindResult occurrence : myOccurrences) {
if (selectionEndOffset >= occurrence.getEndOffset() && selectionStartOffset <= occurrence.getStartOffset()) {
return occurrence;
}
}
return firstOccurrenceAfterCaret();
}
use of com.intellij.find.FindResult in project intellij-community by JetBrains.
the class SearchResults method findInRange.
private void findInRange(TextRange r, Editor editor, FindModel findModel, ArrayList<FindResult> results) {
VirtualFile virtualFile = FileDocumentManager.getInstance().getFile(editor.getDocument());
CharSequence charSequence = editor.getDocument().getCharsSequence();
int offset = r.getStartOffset();
int maxOffset = Math.min(r.getEndOffset(), charSequence.length());
FindManager findManager = FindManager.getInstance(getProject());
while (true) {
FindResult result;
try {
CharSequence bombedCharSequence = StringUtil.newBombedCharSequence(charSequence, 3000);
result = findManager.findString(bombedCharSequence, offset, findModel, virtualFile);
} catch (PatternSyntaxException | ProcessCanceledException e) {
result = null;
}
if (result == null || !result.isStringFound())
break;
int newOffset = result.getEndOffset();
if (result.getEndOffset() > maxOffset)
break;
if (offset == newOffset) {
if (offset < maxOffset - 1) {
offset++;
} else {
results.add(result);
break;
}
} else {
offset = newOffset;
}
results.add(result);
}
}
use of com.intellij.find.FindResult in project intellij-community by JetBrains.
the class SelectionManager method updateSelection.
public void updateSelection(boolean removePreviousSelection, boolean removeAllPreviousSelections) {
Editor editor = mySearchResults.getEditor();
if (removeAllPreviousSelections) {
editor.getCaretModel().removeSecondaryCarets();
}
final FindResult cursor = mySearchResults.getCursor();
if (cursor == null) {
if (removePreviousSelection && !myHadSelectionInitially)
editor.getSelectionModel().removeSelection();
return;
}
if (mySearchResults.getFindModel().isGlobal()) {
if (removePreviousSelection || removeAllPreviousSelections) {
FoldingModel foldingModel = editor.getFoldingModel();
final FoldRegion[] allRegions = editor.getFoldingModel().getAllFoldRegions();
foldingModel.runBatchFoldingOperation(() -> {
for (FoldRegion region : myRegionsToRestore) {
if (region.isValid())
region.setExpanded(false);
}
myRegionsToRestore.clear();
for (FoldRegion region : allRegions) {
if (!region.isValid())
continue;
if (cursor.intersects(TextRange.create(region))) {
if (!region.isExpanded()) {
region.setExpanded(true);
myRegionsToRestore.add(region);
}
}
}
});
editor.getSelectionModel().setSelection(cursor.getStartOffset(), cursor.getEndOffset());
editor.getCaretModel().moveToOffset(cursor.getEndOffset());
} else {
FindUtil.selectSearchResultInEditor(editor, cursor, -1);
}
editor.getScrollingModel().scrollToCaret(ScrollType.CENTER);
} else {
if (!SearchResults.insideVisibleArea(editor, cursor)) {
LogicalPosition pos = editor.offsetToLogicalPosition(cursor.getStartOffset());
editor.getScrollingModel().scrollTo(pos, ScrollType.CENTER);
}
}
}
use of com.intellij.find.FindResult in project intellij-community by JetBrains.
the class LivePreview method highlightUsages.
private void highlightUsages() {
if (mySearchResults.getEditor() == null)
return;
if (mySearchResults.getMatchesCount() >= mySearchResults.getMatchesLimit())
return;
for (FindResult range : mySearchResults.getOccurrences()) {
if (range.getEndOffset() > mySearchResults.getEditor().getDocument().getTextLength())
continue;
TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(EditorColors.TEXT_SEARCH_RESULT_ATTRIBUTES);
if (range.getLength() == 0) {
attributes = attributes.clone();
attributes.setEffectType(EffectType.BOXED);
attributes.setEffectColor(attributes.getBackgroundColor());
}
if (mySearchResults.isExcluded(range)) {
highlightRange(range, strikeout(), myHighlighters);
} else {
highlightRange(range, attributes, myHighlighters);
}
}
updateInSelectionHighlighters();
if (!myListeningSelection) {
mySearchResults.getEditor().getSelectionModel().addSelectionListener(this);
myListeningSelection = true;
}
}
Aggregations