diff --git a/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlay.java b/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlay.java index 9586c243543..613b40c6eda 100644 --- a/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlay.java +++ b/bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlay.java @@ -147,6 +147,37 @@ private final class KeyboardShortcuts { private ControlDecoration searchBarDecoration; private ContentAssistCommandAdapter contentAssistSearchField, contentAssistReplaceField; + private FocusListener inputFieldTargetActionActivation = new FocusListener() { + @Override + public void focusGained(FocusEvent e) { + setTextEditorActionsActivated(false); + } + + @Override + public void focusLost(FocusEvent e) { + setTextEditorActionsActivated(true); + } + + /* + * Adapted from + * org.eclipse.jdt.internal.ui.javaeditor.JavaEditor#setActionsActivated( + * boolean) + */ + private void setTextEditorActionsActivated(boolean state) { + if (!(targetPart instanceof AbstractTextEditor)) { + return; + } + try { + Method method = AbstractTextEditor.class.getDeclaredMethod("setActionActivation", boolean.class); //$NON-NLS-1$ + method.setAccessible(true); + method.invoke(targetPart, Boolean.valueOf(state)); + } catch (IllegalArgumentException | InvocationTargetException | IllegalAccessException | SecurityException | NoSuchMethodException ex) { + TextEditorPlugin.getDefault().getLog() + .log(Status.error("cannot (de-)activate actions for text editor", ex)); //$NON-NLS-1$ + } + } + }; + public FindReplaceOverlay(Shell parent, IWorkbenchPart part, IFindReplaceTarget target) { targetPart = part; targetControl = getTargetControl(parent, part); @@ -560,39 +591,16 @@ private void createSearchBar() { showUserFeedback(normalTextForegroundColor, true); updateIncrementalSearch(); }); + searchBar.addFocusListener(inputFieldTargetActionActivation); searchBar.addFocusListener(new FocusListener() { - @Override public void focusGained(FocusEvent e) { findReplaceLogic.resetIncrementalBaseLocation(); - setTextEditorActionsActivated(false); } - @Override public void focusLost(FocusEvent e) { showUserFeedback(normalTextForegroundColor, false); - setTextEditorActionsActivated(true); } - - /* - * Adapted from - * org.eclipse.jdt.internal.ui.javaeditor.JavaEditor#setActionsActivated( - * boolean) - */ - private void setTextEditorActionsActivated(boolean state) { - if (!(targetPart instanceof AbstractTextEditor)) { - return; - } - try { - Method method = AbstractTextEditor.class.getDeclaredMethod("setActionActivation", boolean.class); //$NON-NLS-1$ - method.setAccessible(true); - method.invoke(targetPart, Boolean.valueOf(state)); - } catch (IllegalArgumentException | InvocationTargetException | IllegalAccessException | SecurityException | NoSuchMethodException ex) { - TextEditorPlugin.getDefault().getLog() - .log(Status.error("cannot (de-)activate actions for text editor", ex)); //$NON-NLS-1$ - } - } - }); searchBar.setMessage(FindReplaceMessages.FindReplaceOverlay_searchBar_message); contentAssistSearchField = createContentAssistField(searchBar, true); @@ -618,6 +626,7 @@ private void createReplaceBar() { replaceBar.addModifyListener(e -> { findReplaceLogic.setReplaceString(replaceBar.getText()); }); + replaceBar.addFocusListener(inputFieldTargetActionActivation); replaceBar.addFocusListener(FocusListener.focusLostAdapter(e -> { replaceBar.setForeground(normalTextForegroundColor); searchBar.setForeground(normalTextForegroundColor);