Skip to content

Commit

Permalink
Find/Replace Overlay: correctly set scope mode
Browse files Browse the repository at this point in the history
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 eclipse-platform#2054
  • Loading branch information
Maximilian Wittmer authored and Maximilian Wittmer committed Jul 8, 2024
1 parent 0e79c18 commit 88f1f62
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ private void updateFromTargetSelection() {
if (initText.isEmpty()) {
return;
}
if (initText.contains(System.lineSeparator())) { // $NON-NLS-1$
if (initText.contains("\n")) { //$NON-NLS-1$
findReplaceLogic.deactivate(SearchOptions.GLOBAL);
searchInSelectionButton.setSelection(true);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,20 @@ public void testActivateDialogWithSelectionActive() {
assertThat(fTextViewer.getDocument().get(), is("text" + System.lineSeparator() + System.lineSeparator()));
}

private void assertScopeActivationOnTextInput(String input) {
openTextViewer(input);
fTextViewer.setSelection(new TextSelection(0, fTextViewer.getDocument().toString().length()));
initializeFindReplaceUIForTextViewer();

dialog.assertUnselected(SearchOptions.GLOBAL);
}

@Test
public void testSelectionOnOpenSetsScopedMode() {
assertScopeActivationOnTextInput("hello\r\nworld\r\nthis\r\nhas_many_lines");
assertScopeActivationOnTextInput("hello\nworld");
}

protected AccessType getDialog() {
return dialog;
}
Expand Down

0 comments on commit 88f1f62

Please sign in to comment.