7272import org .eclipse .ui .internal .findandreplace .FindReplaceMessages ;
7373import org .eclipse .ui .internal .findandreplace .HistoryStore ;
7474import org .eclipse .ui .internal .findandreplace .SearchOptions ;
75- import org .eclipse .ui .internal .findandreplace .status .IFindReplaceStatus ;
7675import org .eclipse .ui .internal .texteditor .TextEditorPlugin ;
7776import org .eclipse .ui .part .MultiPageEditorSite ;
7877
@@ -149,6 +148,8 @@ private final class KeyboardShortcuts {
149148 private Color widgetBackgroundColor ;
150149 private Color overlayBackgroundColor ;
151150 private Color normalTextForegroundColor ;
151+ private Color errorTextForegroundColor ;
152+
152153 private boolean positionAtTop = true ;
153154 private ControlDecoration searchBarDecoration ;
154155 private ContentAssistCommandAdapter contentAssistSearchField , contentAssistReplaceField ;
@@ -336,7 +337,7 @@ public Composite getContainerControl() {
336337 private void performReplaceAll () {
337338 BusyIndicator .showWhile (containerControl .getShell () != null ? containerControl .getShell ().getDisplay () : Display .getCurrent (),
338339 findReplaceLogic ::performReplaceAll );
339- evaluateFindReplaceStatus ();
340+ evaluateStatusAfterReplace ();
340341 replaceBar .storeHistory ();
341342 searchBar .storeHistory ();
342343 }
@@ -460,7 +461,7 @@ private void createContainerAndSearchControls(Composite parent) {
460461 if (insertedInTargetParent ()) {
461462 parent = parent .getParent ();
462463 }
463- retrieveBackgroundColor ();
464+ retrieveColors ();
464465 createMainContainer (parent );
465466 initializeSearchShortcutHandlers ();
466467
@@ -479,7 +480,7 @@ private void initializeSearchShortcutHandlers() {
479480 * would otherwise inherit non-fitting custom colors from the containing
480481 * StyledText.
481482 */
482- private void retrieveBackgroundColor () {
483+ private void retrieveColors () {
483484 if (targetPart instanceof StatusTextEditor textEditor ) {
484485 Control targetWidget = textEditor .getAdapter (ITextViewer .class ).getTextWidget ();
485486 widgetBackgroundColor = targetWidget .getBackground ();
@@ -492,6 +493,7 @@ private void retrieveBackgroundColor() {
492493 textBarForRetrievingTheRightColor .dispose ();
493494 }
494495 overlayBackgroundColor = retrieveDefaultCompositeBackground ();
496+ errorTextForegroundColor = JFaceColors .getErrorText (targetControl .getShell ().getDisplay ());
495497 }
496498
497499 private Color retrieveDefaultCompositeBackground () {
@@ -652,8 +654,6 @@ private void createWholeWordsButton() {
652654 }
653655
654656 private void createReplaceTools () {
655- Color warningColor = JFaceColors .getErrorText (containerControl .getShell ().getDisplay ());
656-
657657 replaceTools = new AccessibleToolBar (replaceContainer );
658658
659659 replaceTools .createToolItem (SWT .SEPARATOR );
@@ -664,7 +664,7 @@ private void createReplaceTools() {
664664 .withToolTipText (FindReplaceMessages .FindReplaceOverlay_replaceButton_toolTip )
665665 .withOperation (() -> {
666666 if (getFindString ().isEmpty ()) {
667- showUserFeedback ( warningColor , true );
667+ applyErrorColor ( replaceBar );
668668 return ;
669669 }
670670 performSingleReplace ();
@@ -675,7 +675,7 @@ private void createReplaceTools() {
675675 .withToolTipText (FindReplaceMessages .FindReplaceOverlay_replaceAllButton_toolTip )
676676 .withOperation (() -> {
677677 if (getFindString ().isEmpty ()) {
678- showUserFeedback ( warningColor , true );
678+ applyErrorColor ( replaceBar );
679679 return ;
680680 }
681681 performReplaceAll ();
@@ -703,9 +703,8 @@ private void createSearchBar() {
703703 searchBar .selectAll ();
704704 searchBar .addModifyListener (e -> {
705705 wholeWordSearchButton .setEnabled (findReplaceLogic .isAvailable (SearchOptions .WHOLE_WORD ));
706-
707- showUserFeedback (normalTextForegroundColor , true );
708706 updateIncrementalSearch ();
707+ decorate ();
709708 });
710709 searchBar .addFocusListener (new FocusListener () {
711710 @ Override
@@ -714,21 +713,18 @@ public void focusGained(FocusEvent e) {
714713 }
715714 @ Override
716715 public void focusLost (FocusEvent e ) {
717- showUserFeedback ( normalTextForegroundColor , false );
716+ resetErrorColoring ( );
718717 }
719718 });
720719 searchBar .addFocusListener (targetActionActivationHandling );
721720 searchBar .setMessage (FindReplaceMessages .FindReplaceOverlay_searchBar_message );
722721 contentAssistSearchField = createContentAssistField (searchBar , true );
723- searchBar .addModifyListener (Event -> {
724- decorate ();
725- });
726722 searchBar .setTabList (null );
727723 }
728724
729725 private void updateIncrementalSearch () {
730726 findReplaceLogic .setFindString (searchBar .getText ());
731- evaluateFindReplaceStatus ();
727+ evaluateStatusAfterFind ();
732728 }
733729
734730 private void createReplaceBar () {
@@ -742,12 +738,10 @@ private void createReplaceBar() {
742738 replaceBar .setMessage (FindReplaceMessages .FindReplaceOverlay_replaceBar_message );
743739 replaceBar .addModifyListener (e -> {
744740 findReplaceLogic .setReplaceString (replaceBar .getText ());
741+ resetErrorColoring ();
745742 });
746743 replaceBar .addFocusListener (targetActionActivationHandling );
747- replaceBar .addFocusListener (FocusListener .focusLostAdapter (e -> {
748- replaceBar .setForeground (normalTextForegroundColor );
749- searchBar .setForeground (normalTextForegroundColor );
750- }));
744+ replaceBar .addFocusListener (FocusListener .focusLostAdapter (e -> resetErrorColoring ()));
751745 contentAssistReplaceField = createContentAssistField (replaceBar , false );
752746 }
753747
@@ -978,8 +972,13 @@ private String getFindString() {
978972 }
979973
980974 private void performSingleReplace () {
981- findReplaceLogic .performReplaceAndFind ();
982- evaluateFindReplaceStatus ();
975+ if (findReplaceLogic .performSelectAndReplace ()) {
976+ findReplaceLogic .performSearch ();
977+ evaluateStatusAfterFind ();
978+ } else {
979+ evaluateStatusAfterReplace ();
980+ }
981+
983982 replaceBar .storeHistory ();
984983 searchBar .storeHistory ();
985984 }
@@ -989,7 +988,7 @@ private void performSearch(boolean forward) {
989988 activateInFindReplacerIf (SearchOptions .FORWARD , forward );
990989 findReplaceLogic .performSearch ();
991990 activateInFindReplacerIf (SearchOptions .FORWARD , oldForwardSearchSetting );
992- evaluateFindReplaceStatus ();
991+ evaluateStatusAfterFind ();
993992 searchBar .storeHistory ();
994993 }
995994
@@ -1008,22 +1007,28 @@ private void updateFromTargetSelection() {
10081007 searchBar .setSelection (0 , searchBar .getText ().length ());
10091008 }
10101009
1011- private void evaluateFindReplaceStatus () {
1012- Color warningColor = JFaceColors .getErrorText (containerControl .getShell ().getDisplay ());
1013- IFindReplaceStatus status = findReplaceLogic .getStatus ();
1010+ private void evaluateStatusAfterFind () {
1011+ resetErrorColoring ();
1012+ if (!findReplaceLogic .getStatus ().wasSuccessful ()) {
1013+ applyErrorColor (searchBar );
1014+ }
1015+ }
10141016
1015- if (!status .wasSuccessful ()) {
1016- boolean colorReplaceBar = okayToUse (replaceBar ) && replaceBar .isFocusControl ();
1017- showUserFeedback (warningColor , colorReplaceBar );
1018- } else {
1019- showUserFeedback (normalTextForegroundColor , false );
1017+ private void evaluateStatusAfterReplace () {
1018+ resetErrorColoring ();
1019+ if (!findReplaceLogic .getStatus ().wasSuccessful ()) {
1020+ applyErrorColor (replaceBar );
10201021 }
10211022 }
10221023
1023- private void showUserFeedback (Color feedbackColor , boolean colorReplaceBar ) {
1024- searchBar .setForeground (feedbackColor );
1025- if (colorReplaceBar && okayToUse (replaceBar )) {
1026- replaceBar .setForeground (feedbackColor );
1024+ private void applyErrorColor (HistoryTextWrapper inputField ) {
1025+ inputField .setForeground (errorTextForegroundColor );
1026+ }
1027+
1028+ private void resetErrorColoring () {
1029+ searchBar .setForeground (normalTextForegroundColor );
1030+ if (okayToUse (replaceBar )) {
1031+ replaceBar .setForeground (normalTextForegroundColor );
10271032 }
10281033 }
10291034
0 commit comments