Skip to content

Commit

Permalink
Fix correctly setting Find-Scopes when opening Find/Replace-Dialog #1819
Browse files Browse the repository at this point in the history


This PR correctly disables SearchOptions.GLOBAL in the FindReplaceLogic
object of the Dialog if a multiline-selection was selected while opening
the Find/Replace-Dialog.

This PR also provides a unit-test for this behavior.

See #1819
  • Loading branch information
Maximilian Wittmer authored and Maximilian Wittmer committed Apr 18, 2024
1 parent f391341 commit ddd9a5e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public interface IFindReplaceLogic {

/**
* {@return whether incremental search may be performed by the
* find/replace-logic based on the currently active options}
* find/replace-logic based on the currently active options.}
*/
public boolean isIncrementalSearchAvailable();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,7 @@ private void initFindStringFromSelection() {
} else {
fGlobalRadioButton.setSelection(false);
fSelectedRangeRadioButton.setSelection(true);
findReplaceLogic.deactivate(SearchOptions.GLOBAL);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ private class DialogAccess {

private Runnable closeOperation;

public Button replaceAllButton;


DialogAccess(Accessor findReplaceDialogAccessor, boolean checkInitialConfiguration) {
findReplaceLogic= (FindReplaceLogic) findReplaceDialogAccessor.get("findReplaceLogic");
Expand All @@ -110,6 +112,7 @@ private class DialogAccess {
incrementalCheckBox= (Button) findReplaceDialogAccessor.get("fIncrementalCheckBox");
regExCheckBox= (Button) findReplaceDialogAccessor.get("fIsRegExCheckBox");
replaceFindButton= (Button) findReplaceDialogAccessor.get("fReplaceFindButton");
replaceAllButton= (Button) findReplaceDialogAccessor.get("fReplaceAllButton");
shellRetriever= () -> ((Shell) findReplaceDialogAccessor.get("fActiveShell"));
closeOperation= () -> findReplaceDialogAccessor.invoke("close", null);
if (checkInitialConfiguration) {
Expand Down Expand Up @@ -426,6 +429,19 @@ public void testActivateWholeWordsAndSearchForTwoWords() {
assertFalse(dialog.wholeWordCheckBox.getEnabled());
}

@Test
public void testActivateDialogWithSelectionActive() {
openTextViewer("text" + System.lineSeparator() + "text" + System.lineSeparator() + "text");
fTextViewer.setSelectedRange(5, 9);
openFindReplaceDialogForTextViewer(false);

assertFalse(dialog.globalRadioButton.getSelection());
dialog.findCombo.setText("text");
dialog.replaceAllButton.notifyListeners(SWT.Selection, null);

assertEquals(fTextViewer.getDocument().get(), "text" + System.lineSeparator() + System.lineSeparator());
}

@Test
public void testIncrementalSearchOnlyEnabledWhenAllowed() {
openTextViewer("text text text");
Expand Down

0 comments on commit ddd9a5e

Please sign in to comment.