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 () {
@@ -744,10 +740,7 @@ private void createReplaceBar() {
744740 findReplaceLogic .setReplaceString (replaceBar .getText ());
745741 });
746742 replaceBar .addFocusListener (targetActionActivationHandling );
747- replaceBar .addFocusListener (FocusListener .focusLostAdapter (e -> {
748- replaceBar .setForeground (normalTextForegroundColor );
749- searchBar .setForeground (normalTextForegroundColor );
750- }));
743+ replaceBar .addFocusListener (FocusListener .focusLostAdapter (e -> resetErrorColoring ()));
751744 contentAssistReplaceField = createContentAssistField (replaceBar , false );
752745 }
753746
@@ -978,8 +971,13 @@ private String getFindString() {
978971 }
979972
980973 private void performSingleReplace () {
981- findReplaceLogic .performReplaceAndFind ();
982- evaluateFindReplaceStatus ();
974+ if (findReplaceLogic .performSelectAndReplace ()) {
975+ findReplaceLogic .performSearch ();
976+ evaluateStatusAfterFind ();
977+ } else {
978+ evaluateStatusAfterReplace ();
979+ }
980+
983981 replaceBar .storeHistory ();
984982 searchBar .storeHistory ();
985983 }
@@ -989,7 +987,7 @@ private void performSearch(boolean forward) {
989987 activateInFindReplacerIf (SearchOptions .FORWARD , forward );
990988 findReplaceLogic .performSearch ();
991989 activateInFindReplacerIf (SearchOptions .FORWARD , oldForwardSearchSetting );
992- evaluateFindReplaceStatus ();
990+ evaluateStatusAfterFind ();
993991 searchBar .storeHistory ();
994992 }
995993
@@ -1008,22 +1006,28 @@ private void updateFromTargetSelection() {
10081006 searchBar .setSelection (0 , searchBar .getText ().length ());
10091007 }
10101008
1011- private void evaluateFindReplaceStatus () {
1012- Color warningColor = JFaceColors .getErrorText (containerControl .getShell ().getDisplay ());
1013- IFindReplaceStatus status = findReplaceLogic .getStatus ();
1009+ private void evaluateStatusAfterFind () {
1010+ resetErrorColoring ();
1011+ if (!findReplaceLogic .getStatus ().wasSuccessful ()) {
1012+ applyErrorColor (searchBar );
1013+ }
1014+ }
10141015
1015- if (!status .wasSuccessful ()) {
1016- boolean colorReplaceBar = okayToUse (replaceBar ) && replaceBar .isFocusControl ();
1017- showUserFeedback (warningColor , colorReplaceBar );
1018- } else {
1019- showUserFeedback (normalTextForegroundColor , false );
1016+ private void evaluateStatusAfterReplace () {
1017+ resetErrorColoring ();
1018+ if (!findReplaceLogic .getStatus ().wasSuccessful ()) {
1019+ applyErrorColor (replaceBar );
10201020 }
10211021 }
10221022
1023- private void showUserFeedback (Color feedbackColor , boolean colorReplaceBar ) {
1024- searchBar .setForeground (feedbackColor );
1025- if (colorReplaceBar && okayToUse (replaceBar )) {
1026- replaceBar .setForeground (feedbackColor );
1023+ private void applyErrorColor (HistoryTextWrapper inputField ) {
1024+ inputField .setForeground (errorTextForegroundColor );
1025+ }
1026+
1027+ private void resetErrorColoring () {
1028+ searchBar .setForeground (normalTextForegroundColor );
1029+ if (okayToUse (replaceBar )) {
1030+ replaceBar .setForeground (normalTextForegroundColor );
10271031 }
10281032 }
10291033
0 commit comments