mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:19:59 +07:00
IJPL-180492 Search tries to find the wrong thing when search field is not focused
Particularly caused by [this commit](5047d0dc16) where I fixed a data race that was caused by `EditorSearchSession.updateResults` called from two different places asynchronously.
But the problem was that the observer that is added inside of `EditorSearchSession` constructor is not invoked when search filed is created and initialized with selected text. So `EditorSearchSession.updateResults` is no longer invoked in this case and therefore `findManager.setFindNextModel(copy);` is not invoked either.
(cherry picked from commit f65df6f4d19495e39e4ab87cb825e94522754118)
IJ-CR-164027
GitOrigin-RevId: 72996444f5d943fc9aceb8f409c8967c0760bf32
This commit is contained in:
committed by
intellij-monorepo-bot
parent
3d443e22b3
commit
7f893ea6d8
@@ -7206,6 +7206,7 @@ f:com.intellij.find.FindUtil
|
||||
- s:showInUsageView(com.intellij.psi.PsiElement,com.intellij.psi.PsiElement[],java.lang.String,com.intellij.openapi.project.Project):com.intellij.usages.UsageView
|
||||
- s:showInUsageView(com.intellij.psi.PsiElement,java.lang.Object[],com.intellij.util.Function,java.lang.String,com.intellij.util.Consumer,com.intellij.openapi.project.Project):com.intellij.usages.UsageView
|
||||
- s:updateFindInFileModel(com.intellij.openapi.project.Project,com.intellij.find.FindModel,Z):V
|
||||
- s:updateFindNextModel(com.intellij.openapi.project.Project,com.intellij.find.FindModel):V
|
||||
- s:useFindStringFromFindInFileModel(com.intellij.find.FindModel,com.intellij.openapi.editor.Editor):V
|
||||
com.intellij.find.FindUtil$ReplaceDelegate
|
||||
- a:shouldReplace(com.intellij.openapi.util.TextRange,java.lang.String):Z
|
||||
|
||||
@@ -160,6 +160,7 @@ public class EditorSearchSession implements SearchSession,
|
||||
mySearchResults.clear();
|
||||
EditorSearchSession.this.updateResults(FindSettings.getInstance().isScrollToResultsDuringTyping());
|
||||
FindUtil.updateFindInFileModel(EditorSearchSession.this.getProject(), myFindModel, !ConsoleViewUtil.isConsoleViewEditor(editor));
|
||||
FindUtil.updateFindNextModel(getProject(), getFindModel());
|
||||
}
|
||||
finally {
|
||||
myReentrantLock = false;
|
||||
@@ -554,7 +555,7 @@ public class EditorSearchSession implements SearchSession,
|
||||
myLivePreviewController.dispose();
|
||||
}
|
||||
|
||||
private void updateResults(final boolean allowedToChangedEditorSelection) {
|
||||
private void updateResults(boolean allowedToChangedEditorSelection) {
|
||||
final String text = myFindModel.getStringToFind();
|
||||
if (text.isEmpty()) {
|
||||
nothingToSearchFor(allowedToChangedEditorSelection);
|
||||
@@ -578,16 +579,6 @@ public class EditorSearchSession implements SearchSession,
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
final FindManager findManager = FindManager.getInstance(getProject());
|
||||
if (allowedToChangedEditorSelection) {
|
||||
findManager.setFindWasPerformed();
|
||||
FindModel copy = new FindModel();
|
||||
copy.copyFrom(myFindModel);
|
||||
copy.setReplaceState(false);
|
||||
findManager.setFindNextModel(copy);
|
||||
}
|
||||
if (myLivePreviewController != null) {
|
||||
myLivePreviewController.updateInBackground(myFindModel, allowedToChangedEditorSelection);
|
||||
}
|
||||
|
||||
@@ -116,6 +116,15 @@ public final class FindUtil {
|
||||
model.setPromptOnReplace(false);
|
||||
}
|
||||
|
||||
public static void updateFindNextModel(@NotNull Project project, @NotNull FindModel with) {
|
||||
FindManager findManager = FindManager.getInstance(project);
|
||||
findManager.setFindWasPerformed();
|
||||
FindModel copy = new FindModel();
|
||||
copy.copyFrom(with);
|
||||
copy.setReplaceState(false);
|
||||
findManager.setFindNextModel(copy);
|
||||
}
|
||||
|
||||
public static void updateFindInFileModel(@Nullable Project project, @NotNull FindModel with, boolean saveFindString) {
|
||||
FindModel model = FindManager.getInstance(project).getFindInFileModel();
|
||||
model.setCaseSensitive(with.isCaseSensitive());
|
||||
|
||||
@@ -57,6 +57,7 @@ public class IncrementalFindAction extends EditorAction implements ActionRemoteB
|
||||
if (!consoleViewEditor && editor.getSelectionModel().hasSelection()) {
|
||||
// selection is used as string to find without search model modification so save the pattern explicitly
|
||||
FindUtil.updateFindInFileModel(project, model, true);
|
||||
FindUtil.updateFindNextModel(project, model);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user