Skip to content

Commit f488dac

Browse files
Maximilian WittmerHeikoKlare
authored andcommitted
Find/Replace Overlay: correctly set scope mode
Depending on the file format, the line separators are different. This PR allows detecting both when deciding whether to set the scoped search mode or not when opening the Overlay with an active selection. fixes #2054
1 parent 7cb5523 commit f488dac

File tree

2 files changed

+15
-1
lines changed
  • bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay
  • tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace

2 files changed

+15
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ private void updateFromTargetSelection() {
907907
if (selectionText.isEmpty()) {
908908
return;
909909
}
910-
if (selectionText.contains(System.lineSeparator())) {
910+
if (selectionText.contains("\n")) { //$NON-NLS-1$
911911
findReplaceLogic.deactivate(SearchOptions.GLOBAL);
912912
searchInSelectionButton.setSelection(true);
913913
} else {

tests/org.eclipse.ui.workbench.texteditor.tests/src/org/eclipse/ui/internal/findandreplace/FindReplaceUITest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,20 @@ public void testActivateDialogWithSelectionActive() {
291291
assertThat(fTextViewer.getDocument().get(), is("text" + System.lineSeparator() + System.lineSeparator()));
292292
}
293293

294+
private void assertScopeActivationOnTextInput(String input) {
295+
openTextViewer(input);
296+
fTextViewer.setSelection(new TextSelection(0, fTextViewer.getDocument().toString().length()));
297+
initializeFindReplaceUIForTextViewer();
298+
299+
dialog.assertUnselected(SearchOptions.GLOBAL);
300+
}
301+
302+
@Test
303+
public void testSelectionOnOpenSetsScopedMode() {
304+
assertScopeActivationOnTextInput("hello\r\nworld\r\nthis\r\nhas_many_lines");
305+
assertScopeActivationOnTextInput("hello\nworld");
306+
}
307+
294308
protected AccessType getDialog() {
295309
return dialog;
296310
}

0 commit comments

Comments
 (0)