feat: ephemeral focus public getter, use in shortcut precondition by maribethb · Pull Request #9110 · RaspberryPiFoundation/blockly
The basics
The details
Resolves
Required for #9101
Proposed Changes
- Adds a public method for whether something has taken ephemeral focus. I called this
ephemeralFocusTakeninstead of matching thecurrentlyHoldsEphemeralFocusbecause I feel like the latter implies that the focus manager is holding it, when really, it's some other object that has taken it. let me know if you hate this though. the name of the property is private so we could probably also change that. cc @BenHenning for feedback on this. - Uses this method in the precondition for most shortcuts (not escape, which hides chaff) in core
Reason for Changes
It's confusing when a keyboard shortcut acts in the "background" of an open field editor. Most shortcuts shouldn't do that. Specific widget divs or dropdown div editors can always bind their own key listeners, or bind a keyboard shortcut that doesn't have this in the precondition. For example, you could imagine the pitch field editor using the up/down arrow keys to move the note up and down the staff. In that case, you would definitely want to disable the keyboard-navigation behavior of the arrow keys while that field editor is open (so you don't navigate between blocks) but you could register your own shortcut that only applies when that editor is open, or just register keypress listeners directly on the field editor.
Test Coverage
Will add webdriver tests when I make the corresponding change in kbe to add this to that plugin's preconditions.
Documentation
We should probably include information about this when explaining ephemeral focus.
Additional Information
cc @RoboErikG this precondition should be included in the cut/copy/paste preconditions, so whichever of us merges second will have to include this in the merge conflict cleanup