Skip to content

Commit 64af72a

Browse files
committed
Find/replace overlay: allow pasting into replace input field #2509
While actions of the target editor are properly deactivated when the find input field of the FindReplaceOverlay has focus, the same does not happen for the replace input field. In consequence, for example, you cannot paste clipboard content into the replace input field via the according keyboard shortcut (CTRL+V). With this change, the functionality to deactivate target editor actions is also applied when the the replace input field has focus, in addition to the find input field. Contributes to #2509
1 parent 7ae2005 commit 64af72a

File tree

1 file changed

+33
-24
lines changed
  • bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay

1 file changed

+33
-24
lines changed

bundles/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/findandreplace/overlay/FindReplaceOverlay.java

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,37 @@ private final class KeyboardShortcuts {
147147
private ControlDecoration searchBarDecoration;
148148
private ContentAssistCommandAdapter contentAssistSearchField, contentAssistReplaceField;
149149

150+
private FocusListener targetActionActivationHandling = new FocusListener() {
151+
@Override
152+
public void focusGained(FocusEvent e) {
153+
setTextEditorActionsActivated(false);
154+
}
155+
156+
@Override
157+
public void focusLost(FocusEvent e) {
158+
setTextEditorActionsActivated(true);
159+
}
160+
161+
/*
162+
* Adapted from
163+
* org.eclipse.jdt.internal.ui.javaeditor.JavaEditor#setActionsActivated(
164+
* boolean)
165+
*/
166+
private void setTextEditorActionsActivated(boolean state) {
167+
if (!(targetPart instanceof AbstractTextEditor)) {
168+
return;
169+
}
170+
try {
171+
Method method = AbstractTextEditor.class.getDeclaredMethod("setActionActivation", boolean.class); //$NON-NLS-1$
172+
method.setAccessible(true);
173+
method.invoke(targetPart, Boolean.valueOf(state));
174+
} catch (IllegalArgumentException | InvocationTargetException | IllegalAccessException | SecurityException | NoSuchMethodException ex) {
175+
TextEditorPlugin.getDefault().getLog()
176+
.log(Status.error("cannot (de-)activate actions for text editor", ex)); //$NON-NLS-1$
177+
}
178+
}
179+
};
180+
150181
public FindReplaceOverlay(Shell parent, IWorkbenchPart part, IFindReplaceTarget target) {
151182
targetPart = part;
152183
targetControl = getTargetControl(parent, part);
@@ -561,39 +592,16 @@ private void createSearchBar() {
561592
updateIncrementalSearch();
562593
});
563594
searchBar.addFocusListener(new FocusListener() {
564-
565595
@Override
566596
public void focusGained(FocusEvent e) {
567597
findReplaceLogic.resetIncrementalBaseLocation();
568-
setTextEditorActionsActivated(false);
569598
}
570-
571599
@Override
572600
public void focusLost(FocusEvent e) {
573601
showUserFeedback(normalTextForegroundColor, false);
574-
setTextEditorActionsActivated(true);
575602
}
576-
577-
/*
578-
* Adapted from
579-
* org.eclipse.jdt.internal.ui.javaeditor.JavaEditor#setActionsActivated(
580-
* boolean)
581-
*/
582-
private void setTextEditorActionsActivated(boolean state) {
583-
if (!(targetPart instanceof AbstractTextEditor)) {
584-
return;
585-
}
586-
try {
587-
Method method = AbstractTextEditor.class.getDeclaredMethod("setActionActivation", boolean.class); //$NON-NLS-1$
588-
method.setAccessible(true);
589-
method.invoke(targetPart, Boolean.valueOf(state));
590-
} catch (IllegalArgumentException | InvocationTargetException | IllegalAccessException | SecurityException | NoSuchMethodException ex) {
591-
TextEditorPlugin.getDefault().getLog()
592-
.log(Status.error("cannot (de-)activate actions for text editor", ex)); //$NON-NLS-1$
593-
}
594-
}
595-
596603
});
604+
searchBar.addFocusListener(targetActionActivationHandling);
597605
searchBar.setMessage(FindReplaceMessages.FindReplaceOverlay_searchBar_message);
598606
contentAssistSearchField = createContentAssistField(searchBar, true);
599607
searchBar.addModifyListener(Event -> {
@@ -618,6 +626,7 @@ private void createReplaceBar() {
618626
replaceBar.addModifyListener(e -> {
619627
findReplaceLogic.setReplaceString(replaceBar.getText());
620628
});
629+
replaceBar.addFocusListener(targetActionActivationHandling);
621630
replaceBar.addFocusListener(FocusListener.focusLostAdapter(e -> {
622631
replaceBar.setForeground(normalTextForegroundColor);
623632
searchBar.setForeground(normalTextForegroundColor);

0 commit comments

Comments
 (0)