mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-200011 Replace in pre-selected text doesn't work any more
This commit is contained in:
@@ -146,15 +146,37 @@ public class EditorSearchSession implements SearchSession,
|
||||
new SwitchToFind(getComponent());
|
||||
new SwitchToReplace(getComponent());
|
||||
|
||||
myFindModel.addObserver(findModel1 -> {
|
||||
String stringToFind = myFindModel.getStringToFind();
|
||||
if (!wholeWordsApplicable(stringToFind)) {
|
||||
myFindModel.setWholeWordsOnly(false);
|
||||
myFindModel.addObserver(new FindModel.FindModelObserver() {
|
||||
boolean myReentrantLock = false;
|
||||
boolean myIsGlobal = myFindModel.isGlobal();
|
||||
boolean myIsReplace = myFindModel.isReplaceState();
|
||||
@Override
|
||||
public void findModelChanged(FindModel findModel1) {
|
||||
if (myReentrantLock) return;
|
||||
try {
|
||||
myReentrantLock = true;
|
||||
String stringToFind = myFindModel.getStringToFind();
|
||||
if (!wholeWordsApplicable(stringToFind)) {
|
||||
myFindModel.setWholeWordsOnly(false);
|
||||
}
|
||||
if (myIsGlobal != myFindModel.isGlobal() || myIsReplace != myFindModel.isReplaceState()) {
|
||||
if (myFindModel.getStringToFind().isEmpty() && myFindModel.isGlobal()) {
|
||||
myFindModel.setStringToFind(StringUtil.notNullize(myEditor.getSelectionModel().getSelectedText(), ""));
|
||||
}
|
||||
if (!myFindModel.isGlobal() && myFindModel.getStringToFind().equals(myEditor.getSelectionModel().getSelectedText())) {
|
||||
myFindModel.setStringToFind("");
|
||||
}
|
||||
myIsGlobal = myFindModel.isGlobal();
|
||||
myIsReplace = myFindModel.isReplaceState();
|
||||
}
|
||||
EditorSearchSession.this.updateUIWithFindModel();
|
||||
mySearchResults.clear();
|
||||
EditorSearchSession.this.updateResults(true);
|
||||
FindUtil.updateFindInFileModel(EditorSearchSession.this.getProject(), myFindModel, !ConsoleViewUtil.isConsoleViewEditor(editor));
|
||||
} finally {
|
||||
myReentrantLock = false;
|
||||
}
|
||||
}
|
||||
updateUIWithFindModel();
|
||||
mySearchResults.clear();
|
||||
updateResults(true);
|
||||
FindUtil.updateFindInFileModel(getProject(), myFindModel, !ConsoleViewUtil.isConsoleViewEditor(editor));
|
||||
});
|
||||
|
||||
updateUIWithFindModel();
|
||||
|
||||
@@ -81,28 +81,23 @@ public class FindUtil {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isMultilineSelection(Editor editor) {
|
||||
SelectionModel selectionModel = editor != null ? editor.getSelectionModel() : null;
|
||||
if (selectionModel != null) {
|
||||
String selectedText = selectionModel.getSelectedText();
|
||||
if (selectedText != null && selectedText.contains("\n")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void configureFindModel(boolean replace, @Nullable Editor editor, FindModel model, boolean firstSearch) {
|
||||
boolean isGlobal = true;
|
||||
String stringToFind = firstSearch ? "" : model.getStringToFind();
|
||||
final SelectionModel selectionModel = editor != null ? editor.getSelectionModel() : null;
|
||||
String selectedText = selectionModel != null ? selectionModel.getSelectedText() : null;
|
||||
if (!StringUtil.isEmpty(selectedText)) {
|
||||
model.setMultiline(isMultilineSelection(editor));
|
||||
stringToFind = selectedText;
|
||||
}
|
||||
model.setReplaceState(replace);
|
||||
boolean multiline = stringToFind.contains("\n");
|
||||
if (replace && multiline) {
|
||||
isGlobal = false;
|
||||
stringToFind = "";
|
||||
multiline = false;
|
||||
}
|
||||
model.setStringToFind(stringToFind);
|
||||
model.setMultiline(multiline);
|
||||
model.setGlobal(isGlobal);
|
||||
model.setPromptOnReplace(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user