From 94aaf665fb77cef85e1ff6046a1e400d2fcbfedb Mon Sep 17 00:00:00 2001 From: Dmitry Batrak Date: Tue, 10 Oct 2017 11:57:40 +0300 Subject: [PATCH] IDEA-179556 Find in updating console --- .../livePreview/LivePreviewController.java | 19 ++-------- .../find/impl/livePreview/SearchResults.java | 35 +++++++++---------- 2 files changed, 20 insertions(+), 34 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/find/impl/livePreview/LivePreviewController.java b/platform/lang-impl/src/com/intellij/find/impl/livePreview/LivePreviewController.java index 10d4be2ac245..651c9632d4fa 100644 --- a/platform/lang-impl/src/com/intellij/find/impl/livePreview/LivePreviewController.java +++ b/platform/lang-impl/src/com/intellij/find/impl/livePreview/LivePreviewController.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.find.impl.livePreview; import com.intellij.find.*; @@ -132,7 +118,8 @@ public class LivePreviewController implements LivePreview.Delegate, FindUtil.Rep if (myDisposed) return; Project project = mySearchResults.getProject(); if (project != null && project.isDisposed()) return; - mySearchResults.updateThreadSafe(copy, allowedToChangedEditorSelection, null, stamp); + mySearchResults.updateThreadSafe(copy, allowedToChangedEditorSelection, null, stamp) + .doWhenRejected(() -> updateInBackground(findModel, allowedToChangedEditorSelection)); }; if (ApplicationManager.getApplication().isUnitTestMode()) { request.run(); 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 52bc9737d19e..44b860aa8d2f 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 @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.find.impl.livePreview; @@ -29,6 +15,7 @@ import com.intellij.openapi.editor.event.DocumentListener; import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.ActionCallback; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.TextRange; import com.intellij.openapi.util.text.StringUtil; @@ -195,9 +182,11 @@ public class SearchResults implements DocumentListener { searchCompleted(new ArrayList<>(), getEditor(), null, false, null, getStamp()); } - void updateThreadSafe(@NotNull FindModel findModel, final boolean toChangeSelection, @Nullable final TextRange next, final int stamp) { - if (myDisposed) return; + ActionCallback updateThreadSafe(@NotNull FindModel findModel, final boolean toChangeSelection, + @Nullable final TextRange next, final int stamp) { + if (myDisposed) return ActionCallback.DONE; + ActionCallback result = new ActionCallback(); final Editor editor = getEditor(); updatePreviousFindModel(findModel); @@ -227,7 +216,16 @@ public class SearchResults implements DocumentListener { } } - final Runnable searchCompletedRunnable = () -> searchCompleted(results, editor, findModel, toChangeSelection, next, stamp); + long documentTimeStamp = editor.getDocument().getModificationStamp(); + final Runnable searchCompletedRunnable = () -> { + if (editor.getDocument().getModificationStamp() == documentTimeStamp) { + searchCompleted(results, editor, findModel, toChangeSelection, next, stamp); + result.setDone(); + } + else { + result.setRejected(); + } + }; if (ApplicationManager.getApplication().isUnitTestMode()) { searchCompletedRunnable.run(); @@ -236,6 +234,7 @@ public class SearchResults implements DocumentListener { UIUtil.invokeLaterIfNeeded(searchCompletedRunnable); } }); + return result; } private void updatePreviousFindModel(@NotNull FindModel model) {