mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fix issue with find (https://devnet.jetbrains.com/thread/475691)
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2000-2014 JetBrains s.r.o.
|
* Copyright 2000-2015 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -19,10 +19,12 @@ import com.intellij.codeInsight.hint.EditorHintListener;
|
|||||||
import com.intellij.find.impl.livePreview.LivePreview;
|
import com.intellij.find.impl.livePreview.LivePreview;
|
||||||
import com.intellij.find.impl.livePreview.LivePreviewController;
|
import com.intellij.find.impl.livePreview.LivePreviewController;
|
||||||
import com.intellij.find.impl.livePreview.SearchResults;
|
import com.intellij.find.impl.livePreview.SearchResults;
|
||||||
|
import com.intellij.openapi.actionSystem.IdeActions;
|
||||||
import com.intellij.openapi.application.ApplicationManager;
|
import com.intellij.openapi.application.ApplicationManager;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.editor.impl.EditorImpl;
|
||||||
import com.intellij.testFramework.LightCodeInsightTestCase;
|
import com.intellij.testFramework.LightCodeInsightTestCase;
|
||||||
import com.intellij.ui.LightweightHint;
|
import com.intellij.testFramework.fixtures.EditorMouseFixture;
|
||||||
|
import com.intellij.util.ui.UIUtil;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
@@ -30,7 +32,6 @@ import java.io.PrintStream;
|
|||||||
public class FindInEditorTest extends LightCodeInsightTestCase {
|
public class FindInEditorTest extends LightCodeInsightTestCase {
|
||||||
|
|
||||||
private LivePreviewController myLivePreviewController;
|
private LivePreviewController myLivePreviewController;
|
||||||
private SearchResults mySearchResults;
|
|
||||||
private FindModel myFindModel;
|
private FindModel myFindModel;
|
||||||
|
|
||||||
private ByteArrayOutputStream myOutputStream;
|
private ByteArrayOutputStream myOutputStream;
|
||||||
@@ -43,36 +44,26 @@ public class FindInEditorTest extends LightCodeInsightTestCase {
|
|||||||
|
|
||||||
myOutputStream = new ByteArrayOutputStream();
|
myOutputStream = new ByteArrayOutputStream();
|
||||||
LivePreview.ourTestOutput = new PrintStream(myOutputStream);
|
LivePreview.ourTestOutput = new PrintStream(myOutputStream);
|
||||||
EditorHintListener listener = new EditorHintListener() {
|
EditorHintListener listener = (project, hint, flags) -> LivePreview.processNotFound();
|
||||||
@Override
|
|
||||||
public void hintShown(Project project, LightweightHint hint, int flags) {
|
|
||||||
LivePreview.processNotFound();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
ApplicationManager.getApplication().getMessageBus().connect(myTestRootDisposable).subscribe(EditorHintListener.TOPIC, listener);
|
ApplicationManager.getApplication().getMessageBus().connect(myTestRootDisposable).subscribe(EditorHintListener.TOPIC, listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initFind() {
|
private void initFind() {
|
||||||
mySearchResults = new SearchResults(getEditor(), getProject());
|
SearchResults searchResults = new SearchResults(getEditor(), getProject());
|
||||||
myLivePreviewController = new LivePreviewController(mySearchResults, null);
|
myLivePreviewController = new LivePreviewController(searchResults, null);
|
||||||
myFindModel.addObserver(new FindModel.FindModelObserver() {
|
myFindModel.addObserver(findModel -> myLivePreviewController.updateInBackground(myFindModel, true));
|
||||||
@Override
|
|
||||||
public void findModelChanged(FindModel findModel) {
|
|
||||||
myLivePreviewController.updateInBackground(myFindModel, true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
myLivePreviewController.on();
|
myLivePreviewController.on();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBasicFind() throws Exception {
|
public void testBasicFind() throws Exception {
|
||||||
configureFromFileText("file.txt", "ab");
|
configureFromText("ab");
|
||||||
initFind();
|
initFind();
|
||||||
myFindModel.setStringToFind("a");
|
myFindModel.setStringToFind("a");
|
||||||
checkResults();
|
checkResults();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testEmacsLikeFallback() throws Exception {
|
public void testEmacsLikeFallback() throws Exception {
|
||||||
configureFromFileText("file.txt", "a\nab");
|
configureFromText("a\nab");
|
||||||
initFind();
|
initFind();
|
||||||
myFindModel.setStringToFind("a");
|
myFindModel.setStringToFind("a");
|
||||||
myFindModel.setStringToFind("ab");
|
myFindModel.setStringToFind("ab");
|
||||||
@@ -81,7 +72,7 @@ public class FindInEditorTest extends LightCodeInsightTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testReplacementWithEmptyString() throws Exception {
|
public void testReplacementWithEmptyString() throws Exception {
|
||||||
configureFromFileText("file.txt", "a");
|
configureFromText("a");
|
||||||
initFind();
|
initFind();
|
||||||
|
|
||||||
myFindModel.setRegularExpressions(true);
|
myFindModel.setRegularExpressions(true);
|
||||||
@@ -93,6 +84,23 @@ public class FindInEditorTest extends LightCodeInsightTestCase {
|
|||||||
checkResults();
|
checkResults();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testSecondFind() throws Exception {
|
||||||
|
configureFromText("<selection>a<caret></selection> b b a");
|
||||||
|
invokeFind();
|
||||||
|
new EditorMouseFixture((EditorImpl)myEditor).doubleClickAt(0, 3);
|
||||||
|
invokeFind();
|
||||||
|
checkResultByText("a <selection>b<caret></selection> b a");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void invokeFind() {
|
||||||
|
executeAction(IdeActions.ACTION_FIND);
|
||||||
|
UIUtil.dispatchAllInvocationEvents();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void configureFromText(String text) {
|
||||||
|
configureFromFileText("file.txt", text);
|
||||||
|
}
|
||||||
|
|
||||||
private void checkResults() {
|
private void checkResults() {
|
||||||
String name = getTestName(false);
|
String name = getTestName(false);
|
||||||
assertSameLinesWithFile(getTestDataPath() + "/find/findInEditor/" + name + ".gold", myOutputStream.toString());
|
assertSameLinesWithFile(getTestDataPath() + "/find/findInEditor/" + name + ".gold", myOutputStream.toString());
|
||||||
|
|||||||
@@ -160,6 +160,7 @@ public class EditorSearchSession implements SearchSession,
|
|||||||
myFindModel.setWholeWordsOnly(false);
|
myFindModel.setWholeWordsOnly(false);
|
||||||
}
|
}
|
||||||
updateUIWithFindModel();
|
updateUIWithFindModel();
|
||||||
|
clearSearchResults();
|
||||||
updateResults(true);
|
updateResults(true);
|
||||||
FindUtil.updateFindInFileModel(getProject(), myFindModel);
|
FindUtil.updateFindInFileModel(getProject(), myFindModel);
|
||||||
}
|
}
|
||||||
@@ -272,7 +273,7 @@ public class EditorSearchSession implements SearchSession,
|
|||||||
updateResults(true);
|
updateResults(true);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
nothingToSearchFor();
|
clearSearchResults();
|
||||||
}
|
}
|
||||||
updateMultiLineStateIfNeed();
|
updateMultiLineStateIfNeed();
|
||||||
}
|
}
|
||||||
@@ -336,10 +337,6 @@ public class EditorSearchSession implements SearchSession,
|
|||||||
mySearchResults.setMatchesLimit(value);
|
mySearchResults.setMatchesLimit(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean canReplaceCurrent() {
|
|
||||||
return myLivePreviewController != null && myLivePreviewController.canReplace();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void replaceCurrent() {
|
public void replaceCurrent() {
|
||||||
if (mySearchResults.getCursor() != null) {
|
if (mySearchResults.getCursor() != null) {
|
||||||
myLivePreviewController.performReplace();
|
myLivePreviewController.performReplace();
|
||||||
@@ -380,7 +377,7 @@ public class EditorSearchSession implements SearchSession,
|
|||||||
private void updateResults(final boolean allowedToChangedEditorSelection) {
|
private void updateResults(final boolean allowedToChangedEditorSelection) {
|
||||||
final String text = myFindModel.getStringToFind();
|
final String text = myFindModel.getStringToFind();
|
||||||
if (text.length() == 0) {
|
if (text.length() == 0) {
|
||||||
nothingToSearchFor();
|
clearSearchResults();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
@@ -413,7 +410,7 @@ public class EditorSearchSession implements SearchSession,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void nothingToSearchFor() {
|
private void clearSearchResults() {
|
||||||
updateUIWithEmptyResults();
|
updateUIWithEmptyResults();
|
||||||
if (mySearchResults != null) {
|
if (mySearchResults != null) {
|
||||||
mySearchResults.clear();
|
mySearchResults.clear();
|
||||||
|
|||||||
Reference in New Issue
Block a user