Skip to content

Commit 47d6592

Browse files
Maximilian WittmerHeikoKlare
authored andcommitted
Find/Replace overlay: escape RegEx on init
When initializing the search text from the selection in the editor, escape the text if it should be interpreted as RegEx fixes #2053
1 parent 118f825 commit 47d6592

File tree

1 file changed

+9
-5
lines changed
  • bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay

1 file changed

+9
-5
lines changed

bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlay.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import org.eclipse.jface.resource.JFaceColors;
5252
import org.eclipse.jface.window.Window;
5353

54+
import org.eclipse.jface.text.FindReplaceDocumentAdapter;
5455
import org.eclipse.jface.text.IFindReplaceTarget;
5556
import org.eclipse.jface.text.IFindReplaceTargetExtension;
5657
import org.eclipse.jface.text.ITextViewer;
@@ -902,16 +903,19 @@ private void performSearch(boolean forward) {
902903
}
903904

904905
private void updateFromTargetSelection() {
905-
String initText = findReplaceLogic.getTarget().getSelectionText();
906-
if (initText.isEmpty()) {
906+
String selectionText = findReplaceLogic.getTarget().getSelectionText();
907+
if (selectionText.isEmpty()) {
907908
return;
908909
}
909-
if (initText.contains(System.lineSeparator())) { // $NON-NLS-1$
910+
if (selectionText.contains(System.lineSeparator())) {
910911
findReplaceLogic.deactivate(SearchOptions.GLOBAL);
911912
searchInSelectionButton.setSelection(true);
912913
} else {
913-
searchBar.setText(initText);
914-
searchBar.setSelection(0, initText.length());
914+
if (findReplaceLogic.isRegExSearchAvailableAndActive()) {
915+
selectionText = FindReplaceDocumentAdapter.escapeForRegExPattern(selectionText);
916+
}
917+
searchBar.setText(selectionText);
918+
searchBar.setSelection(0, selectionText.length());
915919
}
916920
}
917921

0 commit comments

Comments
 (0)