Find/Replace overlay: adopt Eclipse command infrastructure for shortcuts and enablement#4192
Draft
HeikoKlare wants to merge 1 commit into
Conversation
The overlay previously dispatched keyboard shortcuts through custom SWT KeyListeners and toggled button enablement by manipulating ToolItems directly, bypassing the Eclipse key binding framework entirely: shortcuts could not be seen or customized via Preferences > Keys, and user-defined overrides were silently ignored. FindReplaceOverlayAction now extends AbstractHandler, so every overlay operation is a real Eclipse handler. AccessibleToolItem.setAction() derives a ToolItem's enabled state and shortcut-hint tooltip from the action itself (via IHandlerListener and a hint resolved through IBindingService), instead of having them pushed to it explicitly at each call site. A dedicated key-binding context hierarchy, declared in plugin.xml and activated/deactivated with overlay focus, scopes the search- and replace-specific commands separately from the ones common to the whole overlay: findReplaceOverlay (parent, active whenever the overlay has focus) |- findReplaceOverlay.searchFocused (active while the search field has focus) |- findReplaceOverlay.replaceFocused (active while the replace field has focus) Handler activation for the overlay's own commands is registered once per action, scoped by an ACTIVE_FOCUS_CONTROL-based expression backed by IFocusService tracking the search/replace text controls, rather than imperatively activated and deactivated on every focus-gained/-lost event. Fixes eclipse-platform#2015 Prepares eclipse-platform#1912
Contributor
Test Results 855 files ±0 855 suites ±0 51m 49s ⏱️ - 13m 59s For more details on these failures, see this check. Results for commit 4933ee0. ± Comparison against base commit c3e5d57. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
The Find/Replace overlay currently dispatches its keyboard shortcuts through custom SWT
KeyListeners and toggles button enablement by manipulatingToolItems directly. This bypasses the Eclipse key binding framework entirely:This continues the incremental refactoring of the overlay's command handling started in #4164, #4169, #4176, #4178, #4184, and #4185 (see "Builds upon" below): now that a dedicated
FindReplaceOverlayCommandSupportclass owns all the overlay's command-related infrastructure, this change lets it take the next step and represent every overlay operation as a genuine Eclipse handler.Contributes to:
Concept and design
Actions become handlers.
FindReplaceOverlayActionnow extendsAbstractHandler, so every overlay operation (search forward/backward, replace, toggle options, close, ...) is a real Eclipse handler that can be registered with the command framework.AccessibleToolItem.setAction()derives aToolItem's enabled state (viaIHandlerListener) and its shortcut-hint tooltip (resolved throughIBindingService) from the action itself, instead of having both pushed to it explicitly at each call site.A dedicated key-binding context hierarchy is declared in
plugin.xmland activated/deactivated together with overlay focus, so that search- and replace-specific commands are only reachable while the corresponding input field has focus:Handler activation is registered once per action, scoped by an
ACTIVE_FOCUS_CONTROL-basedExpression— backed byIFocusServicetracking the search/replace text controls — rather than being imperatively activated and deactivated on every focus-gained/-lost event. The overlay's own commands are private to it (no other part registers a competing handler for them), so registering on the workbench-levelIHandlerServiceis sufficient to keep them reliably reachable, regardless of how the target editor's own context nesting behaves.The shortcut-hint tooltip still depends on which context is currently active (not on handler activation, which is now permanent), so it continues to be recomputed on every focus transition, exactly as before — just through a single, generic hint-refresh step instead of being interleaved with handler (de)activation.
Out of scope for this change: suppression of the target editor's native text-widget shortcuts (Ctrl+Z/C/V/X/A, arrow keys, etc., so that they act on the overlay's input fields rather than the editor) continues to rely on the existing reflective
setActionActivation/global-action-handler mechanism, unchanged. Replacing that reflection-based workaround is intentionally left to a follow-up (see below) to keep this change focused and reviewable.Builds upon
This is the next step in a series of incremental refactorings of the Find/Replace overlay's command handling:
FindReplaceOverlayActionFindReplaceLogicFollow-ups
This change is itself a stepping stone. Planned follow-ups building on the same command-infrastructure foundation:
setActionActivation/global-action-handler suppression of the target editor's native shortcuts with a proper, non-reflective mechanism built on the same handler/expression infrastructure introduced here.FindReplaceOverlayfromStatusTextEditor, so the overlay can be used with other kinds of targets.How to test
Manually:
Automated: the existing
FindReplaceOverlayTestsuite (org.eclipse.ui.workbench.texteditor.tests) exercises the overlay's search/replace/history/option behavior and passes unchanged.Screenshot
State of Work
I will still give this PR some polishment and probably extract out some further preparatory changes in addition to the ones already mentioned above before submitting this PR. I still wanted to provide it as draft for making aware of this work and for early testing/feedback already.