From 42950d3d2b3b9cbad4dd9cf091046b6db21dbdc5 Mon Sep 17 00:00:00 2001 From: "andrey.zaytsev" Date: Sat, 28 Apr 2012 22:09:10 +0400 Subject: [PATCH] replace when too big number of matches to highlight found. --- .../intellij/find/EditorSearchComponent.java | 2 +- .../find/impl/livePreview/LivePreview.java | 8 +-- .../find/impl/livePreview/SearchResults.java | 51 +++++++++---------- 3 files changed, 29 insertions(+), 32 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/find/EditorSearchComponent.java b/platform/lang-impl/src/com/intellij/find/EditorSearchComponent.java index bcdbe955f479..7e78ce424956 100644 --- a/platform/lang-impl/src/com/intellij/find/EditorSearchComponent.java +++ b/platform/lang-impl/src/com/intellij/find/EditorSearchComponent.java @@ -180,10 +180,10 @@ public class EditorSearchComponent extends EditorHeaderComponent implements Data @Override public void searchResultsUpdated(SearchResults sr) { - int count = sr.getActualFound(); if (mySearchField.getText().isEmpty()) { updateUIWithEmptyResults(); } else { + int count = sr.getMatchesCount(); if (count <= mySearchResults.getMatchesLimit()) { myClickToHighlightLabel.setVisible(false); diff --git a/platform/lang-impl/src/com/intellij/find/impl/livePreview/LivePreview.java b/platform/lang-impl/src/com/intellij/find/impl/livePreview/LivePreview.java index c1146bc66696..930ad22d4706 100644 --- a/platform/lang-impl/src/com/intellij/find/impl/livePreview/LivePreview.java +++ b/platform/lang-impl/src/com/intellij/find/impl/livePreview/LivePreview.java @@ -279,18 +279,20 @@ public class LivePreview extends DocumentAdapter implements ReplacementView.Dele private void highlightUsages() { if (mySearchResults.getEditor() == null) return; + if (mySearchResults.getMatchesCount() >= mySearchResults.getMatchesLimit()) + return; for (LiveOccurrence o : mySearchResults.getOccurrences()) { for (TextRange textRange : o.getSecondaryRanges()) { highlightRange(textRange, OTHER_TARGETS_ATTRIBUTES, myHighlighters); } final TextRange range = o.getPrimaryRange(); - TextAttributes attrs = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(EditorColors.TEXT_SEARCH_RESULT_ATTRIBUTES); + TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(EditorColors.TEXT_SEARCH_RESULT_ATTRIBUTES); if (mySearchResults.isExcluded(o)) { - highlightRange(range, strikout(attrs), myHighlighters); + highlightRange(range, strikout(attributes), myHighlighters); } else { - highlightRange(range, attrs, myHighlighters); + highlightRange(range, attributes, myHighlighters); } } updateInSelectionHighlighters(); diff --git a/platform/lang-impl/src/com/intellij/find/impl/livePreview/SearchResults.java b/platform/lang-impl/src/com/intellij/find/impl/livePreview/SearchResults.java index d9786020670a..3f3f3c5271cf 100644 --- a/platform/lang-impl/src/com/intellij/find/impl/livePreview/SearchResults.java +++ b/platform/lang-impl/src/com/intellij/find/impl/livePreview/SearchResults.java @@ -47,7 +47,6 @@ public class SearchResults implements DocumentListener { public enum Direction {UP, DOWN} - private int myActualFound = 0; private List myListeners = new ArrayList(); @@ -87,8 +86,8 @@ public class SearchResults implements DocumentListener { FindUtil.processNotFound(myEditor, findModel.getStringToFind(), findModel, getProject()); } - public int getActualFound() { - return myActualFound; + public int getMatchesCount() { + return myOccurrences.size(); } public boolean hasMatches() { @@ -191,7 +190,7 @@ public class SearchResults implements DocumentListener { } public void clear() { - searchCompleted(new ArrayList(), 0, getEditor(), null, false, null, getStamp()); + searchCompleted(new ArrayList(), getEditor(), null, false, null, getStamp()); } private static class BombedCharSequence implements CharSequence { @@ -268,14 +267,12 @@ public class SearchResults implements DocumentListener { } } - if (results.size() < myMatchesLimit) { - findResultsToOccurrences(results, occurrences); - } + findResultsToOccurrences(results, occurrences); final Runnable searchCompletedRunnable = new Runnable() { @Override public void run() { - searchCompleted(occurrences, results.size(), editor, findModel, toChangeSelection, next, stamp); + searchCompleted(occurrences, editor, findModel, toChangeSelection, next, stamp); } }; @@ -346,8 +343,6 @@ public class SearchResults implements DocumentListener { if (offset == newOffset || result.getEndOffset() > r.getEndOffset()) break; offset = newOffset; results.add(result); - - if (results.size() > myMatchesLimit) break; } } @@ -356,30 +351,30 @@ public class SearchResults implements DocumentListener { myEditor.getDocument().removeDocumentListener(this); } - private void searchCompleted(List occurrences, int size, Editor editor, @Nullable FindModel findModel, + private void searchCompleted(List occurrences, Editor editor, @Nullable FindModel findModel, boolean toChangeSelection, @Nullable TextRange next, int stamp) { if (stamp < myLastUpdatedStamp){ return; } myLastUpdatedStamp = stamp; - if (editor == getEditor() && !myDisposed) { - myOccurrences = occurrences; - final TextRange oldCursorRange = myCursor != null ? myCursor.getPrimaryRange() : null; - Collections.sort(myOccurrences, new Comparator() { - @Override - public int compare(LiveOccurrence liveOccurrence, LiveOccurrence liveOccurrence1) { - return liveOccurrence.getPrimaryRange().getStartOffset() - liveOccurrence1.getPrimaryRange().getStartOffset(); - } - }); - - myFindModel = findModel; - updateCursor(oldCursorRange, next); - updateExcluded(); - myActualFound = size; - notifyChanged(); - if (oldCursorRange == null || myCursor == null || !myCursor.getPrimaryRange().equals(oldCursorRange)) { - notifyCursorMoved(toChangeSelection); + if (editor != getEditor() || myDisposed) { + return; + } + myOccurrences = occurrences; + final TextRange oldCursorRange = myCursor != null ? myCursor.getPrimaryRange() : null; + Collections.sort(myOccurrences, new Comparator() { + @Override + public int compare(LiveOccurrence liveOccurrence, LiveOccurrence liveOccurrence1) { + return liveOccurrence.getPrimaryRange().getStartOffset() - liveOccurrence1.getPrimaryRange().getStartOffset(); } + }); + + myFindModel = findModel; + updateCursor(oldCursorRange, next); + updateExcluded(); + notifyChanged(); + if (oldCursorRange == null || myCursor == null || !myCursor.getPrimaryRange().equals(oldCursorRange)) { + notifyCursorMoved(toChangeSelection); } }