diff --git a/platform/lang-impl/src/com/intellij/find/impl/FindDialog.java b/platform/lang-impl/src/com/intellij/find/impl/FindDialog.java index 96be30519e45..4fb8d6cb6836 100644 --- a/platform/lang-impl/src/com/intellij/find/impl/FindDialog.java +++ b/platform/lang-impl/src/com/intellij/find/impl/FindDialog.java @@ -496,6 +496,9 @@ public class FindDialog extends DialogWrapper implements FindUI { Ref lastUsageFileRef = new Ref<>(); FindInProjectUtil.findUsages(findModel, myProject, info -> { + if(isCancelled()) { + return false; + } final Usage usage = UsageInfo2UsageAdapter.CONVERTER.fun(info); usage.getPresentation().getIcon(); // cache icon @@ -507,6 +510,7 @@ public class FindDialog extends DialogWrapper implements FindUI { } ApplicationManager.getApplication().invokeLater(() -> { + if (isCancelled()) return; model.addRow(new Object[]{usage}); }, state); return resultsCount.incrementAndGet() < ShowUsagesAction.USAGES_PAGE_SIZE; @@ -515,7 +519,7 @@ public class FindDialog extends DialogWrapper implements FindUI { boolean succeeded = !progressIndicatorWhenSearchStarted.isCanceled(); if (succeeded) { return new Continuation(() -> { - if (progressIndicatorWhenSearchStarted == myResultsPreviewSearchProgress && !myResultsPreviewSearchProgress.isCanceled()) { + if (!isCancelled()) { int occurrences = resultsCount.get(); int filesWithOccurrences = resultsFilesCount.get(); if (occurrences == 0) myResultsPreviewTable.getEmptyText().setText(UIBundle.message("message.nothingToShow")); @@ -534,6 +538,10 @@ public class FindDialog extends DialogWrapper implements FindUI { return null; } + boolean isCancelled() { + return progressIndicatorWhenSearchStarted != myResultsPreviewSearchProgress || myResultsPreviewSearchProgress.isCanceled(); + } + @Override public void onCanceled(@NotNull ProgressIndicator indicator) { if (isShowing() && progressIndicatorWhenSearchStarted == myResultsPreviewSearchProgress) { diff --git a/platform/lang-impl/src/com/intellij/find/impl/FindPopupPanel.java b/platform/lang-impl/src/com/intellij/find/impl/FindPopupPanel.java index 192559368df5..3c3225d570f2 100644 --- a/platform/lang-impl/src/com/intellij/find/impl/FindPopupPanel.java +++ b/platform/lang-impl/src/com/intellij/find/impl/FindPopupPanel.java @@ -809,6 +809,9 @@ public class FindPopupPanel extends JBPanel implements FindUI, DataProvider { Ref lastUsageFileRef = new Ref<>(); FindInProjectUtil.findUsages(myHelper.getModel().clone(), myProject, info -> { + if(isCancelled()) { + return false; + } final Usage usage = UsageInfo2UsageAdapter.CONVERTER.fun(info); usage.getPresentation().getIcon(); // cache icon @@ -820,6 +823,9 @@ public class FindPopupPanel extends JBPanel implements FindUI, DataProvider { } ApplicationManager.getApplication().invokeLater(() -> { + if(isCancelled()) { + return; + } model.addRow(new Object[]{usage}); myCodePreviewComponent.setVisible(true); if (model.getRowCount() == 1 && myResultsPreviewTable.getModel() == model) { @@ -832,7 +838,7 @@ public class FindPopupPanel extends JBPanel implements FindUI, DataProvider { boolean succeeded = !progressIndicatorWhenSearchStarted.isCanceled(); if (succeeded) { ApplicationManager.getApplication().invokeLater(() -> { - if (progressIndicatorWhenSearchStarted == myResultsPreviewSearchProgress && !myResultsPreviewSearchProgress.isCanceled()) { + if (!isCancelled()) { int occurrences = resultsCount.get(); int filesWithOccurrences = resultsFilesCount.get(); if (occurrences == 0) myResultsPreviewTable.getEmptyText().setText(UIBundle.message("message.nothingToShow")); @@ -858,6 +864,10 @@ public class FindPopupPanel extends JBPanel implements FindUI, DataProvider { } } + boolean isCancelled() { + return progressIndicatorWhenSearchStarted != myResultsPreviewSearchProgress || progressIndicatorWhenSearchStarted.isCanceled(); + } + @Override public void onCanceled(@NotNull ProgressIndicator indicator) { if (isShowing() && progressIndicatorWhenSearchStarted == myResultsPreviewSearchProgress) {