Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import static org.eclipse.ui.internal.findandreplace.FindReplaceTestUtil.waitForFocus;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
Expand All @@ -29,7 +30,10 @@

import org.eclipse.text.tests.Accessor;

import org.eclipse.jface.viewers.ISelection;

import org.eclipse.jface.text.IFindReplaceTarget;
import org.eclipse.jface.text.IMultiTextSelection;
import org.eclipse.jface.text.TextViewer;

import org.eclipse.ui.internal.findandreplace.FindReplaceUITest;
Expand Down Expand Up @@ -227,6 +231,49 @@ public void testSearchTermStoredInHistoryAfterSearchBackward() {
assertEquals("foo", dialog.getFindText());
}

@Test
public void testReplaceDoesNothingIfSearchStringIsEmpty() {
// The overlay refuses replace operations as long as the search string is
// empty; the document must remain unchanged.
initializeTextViewerWithFindReplaceUI("text text");
OverlayAccess dialog= getDialog();
dialog.setReplaceText("replacement");

dialog.performReplace();
assertThat(getTextViewer().getDocument().get(), is("text text"));

dialog.performReplaceAll();
assertThat(getTextViewer().getDocument().get(), is("text text"));
}

@Test
public void testSelectAllSelectsAllOccurrences() {
initializeTextViewerWithFindReplaceUI("foo bar foo bar foo");
OverlayAccess dialog= getDialog();
dialog.setFindText("foo");

dialog.pressSelectAll();

ISelection selection= getTextViewer().getSelection();
assertThat(selection, is(instanceOf(IMultiTextSelection.class)));
assertEquals(3, ((IMultiTextSelection) selection).getRegions().length);
}

@Test
public void testSearchTermStoredInHistoryAfterSelectAll() {
// Selecting all occurrences must persist the search term to history just
// like the other search operations.
initializeTextViewerWithFindReplaceUI("foo bar foo");
OverlayAccess dialog= getDialog();
dialog.setFindText("foo");
dialog.pressSelectAll();

dialog.setFindText("");
dialog.simulateKeyboardInteractionInFindInputField(SWT.ARROW_DOWN, false);

assertEquals("foo", dialog.getFindText());
}

@Test
public void testSearchInSelectionButtonIsInverseOfGlobalOption() {
// The searchInSelection button is the inverse of the GLOBAL option:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class OverlayAccess implements IFindReplaceUIAccess {

private final ToolItem searchBackward;

private final ToolItem selectAll;

private final ToolItem openReplaceDialog;

private HistoryTextWrapper replace;
Expand All @@ -74,6 +76,7 @@ class OverlayAccess implements IFindReplaceUIAccess {
inSelection= widgetExtractor.findToolItem("searchInSelection");
searchForward= widgetExtractor.findToolItem("searchForward");
searchBackward= widgetExtractor.findToolItem("searchBackward");
selectAll= widgetExtractor.findToolItem("selectAll");
openReplaceDialog= widgetExtractor.findToolItem("replaceToggle");
extractReplaceWidgets();
}
Expand Down Expand Up @@ -227,6 +230,10 @@ public void selectFindHistoryEntry(int index) {
}
}

public void pressSelectAll() {
selectAll.notifyListeners(SWT.Selection, null);
}

public void pressSearch(boolean forward) {
if (forward) {
searchForward.notifyListeners(SWT.Selection, null);
Expand Down
Loading