IDEA-102111 Keep search/replace words between files

This commit is contained in:
Maxim.Mossienko
2016-09-15 14:31:16 +02:00
parent e88faa03f6
commit 5fa655fe6c
3 changed files with 15 additions and 4 deletions
@@ -16,6 +16,7 @@
package com.intellij.find;
import com.intellij.execution.impl.ConsoleViewUtil;
import com.intellij.find.editorHeaderActions.*;
import com.intellij.find.impl.livePreview.LivePreviewController;
import com.intellij.find.impl.livePreview.SearchResults;
@@ -154,7 +155,7 @@ public class EditorSearchSession implements SearchSession,
updateUIWithFindModel();
mySearchResults.clear();
updateResults(true);
FindUtil.updateFindInFileModel(getProject(), myFindModel);
FindUtil.updateFindInFileModel(getProject(), myFindModel, !ConsoleViewUtil.isConsoleViewEditor(editor));
}
});
@@ -143,14 +143,20 @@ public class FindUtil {
model.setPromptOnReplace(false);
}
public static void updateFindInFileModel(@Nullable Project project, @NotNull FindModel with) {
public static void updateFindInFileModel(@Nullable Project project, @NotNull FindModel with, boolean saveFindString) {
FindModel model = FindManager.getInstance(project).getFindInFileModel();
model.setCaseSensitive(with.isCaseSensitive());
model.setWholeWordsOnly(with.isWholeWordsOnly());
model.setRegularExpressions(with.isRegularExpressions());
model.setSearchContext(with.getSearchContext());
if (saveFindString && !with.getStringToFind().isEmpty()) {
model.setStringToFind(with.getStringToFind());
}
if (with.isReplaceState()) {
model.setPreserveCase(with.isPreserveCase());
if (saveFindString) model.setStringToReplace(with.getStringToReplace());
}
}
@@ -28,7 +28,6 @@ import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.actionSystem.EditorAction;
import com.intellij.openapi.editor.actionSystem.EditorActionHandler;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.wm.IdeFocusManager;
public class IncrementalFindAction extends EditorAction {
public static class Handler extends EditorActionHandler {
@@ -57,9 +56,14 @@ public class IncrementalFindAction extends EditorAction {
model = new FindModel();
model.copyFrom(findManager.getFindInFileModel());
}
FindUtil.configureFindModel(myReplace, editor, model, true);
boolean consoleViewEditor = ConsoleViewUtil.isConsoleViewEditor(editor);
FindUtil.configureFindModel(myReplace, editor, model, consoleViewEditor);
EditorSearchSession.start(editor, model, project).getComponent()
.requestFocusInTheSearchFieldAndSelectContent(project);
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);
}
}
}
}