From 742846bf11bac1539b4ba74f0826c3c1354f95b5 Mon Sep 17 00:00:00 2001 From: Maximilian Wittmer Date: Sat, 6 Jul 2024 11:17:04 +0200 Subject: [PATCH] Find/Replace Overlay: close when escape is pressed in the editor When escape is pressed inside of the editor which is targeted by the find/replace overlay, the overlay now closes. fixes #2033 --- .../findandreplace/overlay/FindReplaceOverlay.java | 7 +++++++ 1 file changed, 7 insertions(+) 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 cbbcaf98f7c..3508cbdabce 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 @@ -302,6 +302,11 @@ private void focusTargetWidget() { targetWidget.forceFocus(); } }; + private KeyListener closeOnTargetEscapeListener = KeyListener.keyPressedAdapter(c -> { + if (c.keyCode == SWT.ESC) { + this.close(); + } + }); private boolean isPartCurrentlyDisplayedInPartSash() { IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); @@ -409,6 +414,7 @@ private void unbindListeners() { if (targetWidget != null) { targetWidget.getShell().removeControlListener(shellMovementListener); targetWidget.removePaintListener(widgetMovementListener); + targetWidget.removeKeyListener(closeOnTargetEscapeListener); targetPart.getSite().getPage().removePartListener(partListener); } } @@ -421,6 +427,7 @@ private void bindListeners() { targetWidget.getShell().addControlListener(shellMovementListener); targetWidget.addPaintListener(widgetMovementListener); + targetWidget.addKeyListener(closeOnTargetEscapeListener); targetPart.getSite().getPage().addPartListener(partListener); } }