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 @@ -132,12 +132,11 @@ private void resetStatus() {
@Override
public boolean isAvailable(SearchOptions searchOption) {
switch (searchOption) {
case INCREMENTAL:
return !isAvailableAndActive(SearchOptions.REGEX);
case REGEX:
return isTargetSupportingRegEx;
case WHOLE_WORD:
return !isAvailableAndActive(SearchOptions.REGEX) && isWord(findString);
case INCREMENTAL:
case CASE_SENSITIVE:
case FORWARD:
case GLOBAL:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@ public void widgetSelected(SelectionEvent e) {
return;
}
findReplaceLogic.activate(SearchOptions.GLOBAL);
updateFindString();
}

@Override
Expand All @@ -608,6 +609,7 @@ public void widgetSelected(SelectionEvent e) {
return;
}
findReplaceLogic.deactivate(SearchOptions.GLOBAL);
updateFindString();
}

@Override
Expand Down Expand Up @@ -650,11 +652,7 @@ private Composite createInputPanel(Composite parent) {
ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS, new char[0], true);
setGridData(fFindField, SWT.FILL, true, SWT.CENTER, false);
addDecorationMargin(fFindField);
fFindModifyListener = new InputModifyListener(() -> {
if (okToUse(fFindField)) {
findReplaceLogic.setFindString(fFindField.getText());
}
});
fFindModifyListener = new InputModifyListener(this::updateFindString);
fFindField.addModifyListener(fFindModifyListener);

fReplaceLabel = new Label(panel, SWT.LEFT);
Expand All @@ -680,6 +678,12 @@ private Composite createInputPanel(Composite parent) {
return panel;
}

private void updateFindString() {
if (okToUse(fFindField)) {
findReplaceLogic.setFindString(fFindField.getText());
}
}

/**
* Creates the functional options part of the options defining section of the
* find replace dialog.
Expand Down Expand Up @@ -708,6 +712,7 @@ private Composite createOptionsGroup(Composite parent) {
public void widgetSelected(SelectionEvent e) {
setupFindReplaceLogic();
storeSettings();
updateFindString();
}

@Override
Expand Down Expand Up @@ -745,6 +750,7 @@ public void widgetDefaultSelected(SelectionEvent e) {
public void widgetSelected(SelectionEvent e) {
setupFindReplaceLogic();
storeSettings();
updateFindString();
}

@Override
Expand All @@ -770,7 +776,7 @@ public void widgetSelected(SelectionEvent e) {
storeSettings();
updateButtonState();
setContentAssistsEnablement(newState);
fIncrementalCheckBox.setEnabled(findReplaceLogic.isAvailable(SearchOptions.INCREMENTAL));
updateFindString();
}
});
storeButtonWithMnemonicInMap(fIsRegExCheckBox);
Expand All @@ -779,9 +785,9 @@ public void widgetSelected(SelectionEvent e) {
@Override
public void widgetSelected(SelectionEvent e) {
updateButtonState();
updateFindString();
}
});
fIncrementalCheckBox.setEnabled(findReplaceLogic.isAvailable(SearchOptions.INCREMENTAL));
return panel;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,17 +212,25 @@ public void testFindWithWholeWordEnabledWithMultipleWords() {
@Test
public void testRegExSearch() {
initializeTextViewerWithFindReplaceUI("abc");
dialog.select(SearchOptions.REGEX);
dialog.select(SearchOptions.INCREMENTAL);
dialog.setFindText("(a|bc)");
dialog.select(SearchOptions.REGEX);

IFindReplaceTarget target= getFindReplaceTarget();
dialog.simulateKeyboardInteractionInFindInputField(SWT.CR, false);
assertEquals(0, (target.getSelection()).x);
assertEquals(1, (target.getSelection()).y);

dialog.simulateKeyboardInteractionInFindInputField(SWT.CR, false);
assertEquals(1, (target.getSelection()).x);
assertEquals(2, (target.getSelection()).y);

dialog.simulateKeyboardInteractionInFindInputField(SWT.CR, false);
assertEquals(0, (target.getSelection()).x);
assertEquals(1, (target.getSelection()).y);

dialog.setFindText("b|c");
assertEquals(1, (target.getSelection()).x);
assertEquals(1, (target.getSelection()).y);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ public void testSearchBackwardsWithRegEx() {

OverlayAccess dialog= getDialog();
dialog.select(SearchOptions.REGEX);
dialog.setFindText("text"); // with RegEx enabled, there is no incremental search!
dialog.pressSearch(true);
dialog.setFindText("text");
assertThat(target.getSelection().y, is(4));
dialog.pressSearch(true);
assertThat(target.getSelection().x, is("text ".length()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,18 +163,6 @@ public void testReplaceAndFindAfterInitializingFindWithSelectedString() {
assertEquals(4, (target.getSelection()).y);
}

@Test
public void testIncrementalSearchOnlyEnabledWhenAllowed() {
initializeTextViewerWithFindReplaceUI("text text text");
DialogAccess dialog= getDialog();

dialog.select(SearchOptions.INCREMENTAL);
dialog.select(SearchOptions.REGEX);

dialog.assertSelected(SearchOptions.INCREMENTAL);
dialog.assertDisabled(SearchOptions.INCREMENTAL);
}

/*
* Test for https://github.com/eclipse-platform/eclipse.platform.ui/pull/1805#pullrequestreview-1993772378
*/
Expand All @@ -191,15 +179,6 @@ public void testIncrementalSearchOptionRecoveredCorrectly() {
dialog= getDialog();
dialog.assertSelected(SearchOptions.INCREMENTAL);
dialog.assertEnabled(SearchOptions.INCREMENTAL);

dialog.select(SearchOptions.REGEX);
dialog.assertSelected(SearchOptions.INCREMENTAL);
dialog.assertDisabled(SearchOptions.INCREMENTAL);

reopenFindReplaceUIForTextViewer();
dialog= getDialog();
dialog.assertSelected(SearchOptions.INCREMENTAL);
dialog.assertDisabled(SearchOptions.INCREMENTAL);
}

@Test
Expand All @@ -225,4 +204,22 @@ public void testFindWithWholeWordEnabledWithMultipleWordsNotIncremental() {
assertEquals(0, (target.getSelection()).x);
assertEquals(dialog.getFindText().length(), (target.getSelection()).y);
}

@Test
public void testRegExSearch_nonIncremental() {
initializeTextViewerWithFindReplaceUI("abc");
DialogAccess dialog= getDialog();
dialog.setFindText("(a|bc)");
dialog.select(SearchOptions.REGEX);

IFindReplaceTarget target= getFindReplaceTarget();
dialog.simulateKeyboardInteractionInFindInputField(SWT.CR, false);
assertEquals(0, (target.getSelection()).x);
assertEquals(1, (target.getSelection()).y);

dialog.simulateKeyboardInteractionInFindInputField(SWT.CR, false);
assertEquals(1, (target.getSelection()).x);
assertEquals(2, (target.getSelection()).y);
}

}
Loading