IDEA-179556 Find in updating console

This commit is contained in:
Dmitry Batrak
2017-10-10 11:59:10 +03:00
parent 4bf04ac293
commit 94aaf665fb
2 changed files with 20 additions and 34 deletions
@@ -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();
@@ -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) {