Allow using the scene editor shortcuts without clicking on the canvas first - #8938
Open
Bouh wants to merge 3 commits into
Open
Allow using the scene editor shortcuts without clicking on the canvas first#8938Bouh wants to merge 3 commits into
Bouh wants to merge 3 commits into
Conversation
Keyboard shortcuts were listened on the canvas itself, which required clicking on it to give it focus. Listen on the window instead, and handle the shortcuts when the canvas is either hovered or focused, so that the space key can be used to move the view right away (like the mouse wheel zoom already did).
…ts handling The in-game editor runs in an iframe, which is a separate document only receiving keyboard events when focused: give it the focus as soon as it is hovered, so that its shortcuts (notably space to move the view) can be used without clicking on the game first. In the instances editor, reuse the `isActive` option of KeyboardShortcuts instead of filtering the events in wrappers, and always handle key releases so that releasing a key after leaving the canvas (which happens when moving the view up to its border) doesn't leave it considered as pressed.
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.
This PR allows using space bar panning without having to focus the canvas.
It removes a currently mandatory focus click. This is much more consistent with mouse wheel zoom, which doesn't need focus to work.
Moreover, it makes the workflow smoother and more pleasant.
Tested on web with the 2D and 3D views in editor.
Claude Code said:
Problem
In the scene editor, the mouse wheel zoom works as soon as the canvas is hovered, but the keyboard shortcuts (notably space to move the view) require clicking on the canvas first. Clicking in any panel, for example the objects list, is enough to lose them.
Two different causes, one per editor:
keydown/keyupwere listened on the canvas itself, which hastabIndex = -1, so the events only arrived when it was focused.<iframe>, a separate document that only receives keyboard events when it has the focus.Changes
Instances editor (
InstancesEditor/index.js): the shortcuts are listened on thewindowand restricted to this editor by theisActiveoption ofKeyboardShortcuts, which is true when the canvas is hovered or focused. The capture phase is used so that a focused component stopping the event propagation (the tree views handle the keyboard) can't prevent them from working. Key releases are always handled, so that releasing a key after leaving the canvas (which happens when moving the view up to its border) doesn't leave it considered as pressed, and the modifiers are reset when the window is blurred (Alt+Tab with a key held down).In-game editor (
EmbeddedGameFrame.js): the iframe is given the focus as soon as it is hovered, with the same call that is already made when a preview is attached. The listener is on the iframe itself, so the overlay covering it (drop target, pointer events blocker) never triggers it.The focus is not taken when a text is being edited (renaming an object, editing a property...) nor when a dialog is opened, to avoid interrupting the user or fighting with a focus trap. Nothing changes for touch devices: only
KeyboardEvents are involved, the pinch and touch gestures go through their own handlers.Testing