Search in sources :

Example 11 with FindResult

use of com.intellij.find.FindResult in project intellij-community by JetBrains.

the class SearchResults method repairCursorFromStack.

private boolean repairCursorFromStack() {
    if (myCursorPositions.size() >= 2) {
        final Pair<FindModel, FindResult> oldPosition = myCursorPositions.get(myCursorPositions.size() - 2);
        if (oldPosition.first.equals(myFindModel)) {
            FindResult newCursor;
            if ((newCursor = findOccurrenceEqualTo(oldPosition.second)) != null) {
                myCursorPositions.pop();
                myCursor = newCursor;
                return true;
            }
        }
    }
    return false;
}
Also used : FindModel(com.intellij.find.FindModel) FindResult(com.intellij.find.FindResult)

Example 12 with FindResult

use of com.intellij.find.FindResult in project intellij-community by JetBrains.

the class SearchResults method nextOccurrence.

private void nextOccurrence(boolean processFromTheBeginning, TextRange cursor, boolean toNotify, boolean justReplaced, boolean retainOldSelection) {
    FindResult next;
    if (myNotFoundState) {
        myNotFoundState = false;
        processFromTheBeginning = true;
    }
    if ((!myFindModel.isGlobal() || justReplaced) && cursor != null) {
        next = nextOccurrence(cursor);
    } else {
        next = firstOccurrenceAfterCaret();
    }
    if (next == null) {
        if (processFromTheBeginning) {
            if (hasMatches()) {
                next = getOccurrences().get(0);
            }
        } else {
            setNotFoundState(true);
        }
    }
    if (toNotify) {
        moveCursorTo(next, retainOldSelection);
    } else {
        myCursor = next;
    }
}
Also used : FindResult(com.intellij.find.FindResult)

Example 13 with FindResult

use of com.intellij.find.FindResult in project intellij-community by JetBrains.

the class SearchResults method updateCursor.

private void updateCursor(@Nullable TextRange oldCursorRange, @Nullable TextRange next) {
    boolean justReplaced = next != null;
    boolean toPush = true;
    if (justReplaced || (toPush = !repairCursorFromStack())) {
        if (justReplaced || !tryToRepairOldCursor(oldCursorRange)) {
            if (myFindModel != null) {
                if (oldCursorRange != null && !myFindModel.isGlobal()) {
                    myCursor = firstOccurrenceAfterOffset(oldCursorRange.getEndOffset());
                } else {
                    if (justReplaced) {
                        nextOccurrence(false, next, false, true, false);
                    } else {
                        FindResult afterCaret = oldCursorRange == null ? firstOccurrenceAtOrAfterCaret() : firstOccurrenceAfterCaret();
                        if (afterCaret != null) {
                            myCursor = afterCaret;
                        } else {
                            myCursor = null;
                        }
                    }
                }
            } else {
                myCursor = null;
            }
        }
    }
    if (!justReplaced && myCursor == null && hasMatches()) {
        nextOccurrence(true, oldCursorRange, false, false, false);
    }
    if (toPush && myCursor != null) {
        push();
    }
}
Also used : FindResult(com.intellij.find.FindResult)

Aggregations

FindResult (com.intellij.find.FindResult)13 FindModel (com.intellij.find.FindModel)3 Editor (com.intellij.openapi.editor.Editor)3 FindManager (com.intellij.find.FindManager)2 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 Document (com.intellij.openapi.editor.Document)1 RangeHighlighter (com.intellij.openapi.editor.markup.RangeHighlighter)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 Project (com.intellij.openapi.project.Project)1 Segment (com.intellij.openapi.util.Segment)1 TextRange (com.intellij.openapi.util.TextRange)1 FutureResult (com.intellij.util.concurrency.FutureResult)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ExecutionException (java.util.concurrent.ExecutionException)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1 Nullable (org.jetbrains.annotations.Nullable)1