8000 feat: Paste where context menu was opened by johnnesky · Pull Request #9093 · google/blockly · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: Paste where context menu was opened #9093

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 27, 2025

Conversation

johnnesky
Copy link
Member
@johnnesky johnnesky commented May 24, 2025

The basics

The details

Resolves

Fixes #9088

Proposed Changes

I updated the KeyboardShortcut callback for pasteShortcut to detect whether the initiating event is a PointerEvent, in which case it infers that the callback was called by a context menu item that wraps the callback. (Otherwise, the event would typically be a KeyboardEvent.) If a context menu was used, then the location of the PointerEvent is used as the location where the block will be pasted.

Reason for Changes

It is commonly expected that if a context menu is used to add a block, then the block will be added where the context menu was opened.

Test Coverage

I have not created any new unit tests for this yet.

Documentation

Probably none needed beyond the code comment I added, although the behavior might be unexpected if someone encounters a different situation where a KeyboardShortcut callback sees a PointerEvent, or if a different context menu implementation forwards events differently.

Additional Information

There are a few ways we could implement this. I think the above strategy is the least amount of code changes and the only solution that can be done in a single PR, but it makes some assumptions.

Alternatively, we could alter the API of KeyboardShortcuts to allow explicitly providing a location at which to apply the shortcut's effects, and then update the context menu item wrapper (which is in a different repo) to provide this location. This strategy might be a little more robust, although it's a little weird that a KeyboardShortcut is being used for an action that has a location in the first place and this would just be further committing to that weirdness.

Maybe a better alternative would be to refactor the copying and pasting to be public functions outside of the KeyboardShortcut interface, so that external code can call them more directly. Notably, there's an existing copyInternal function that could be useful for this, but it's currently private to core Blockly and it doesn't share clipboard data with the KeyboardShortcut version for some reason. After we make these changes to this repo, we would need to update the external repo to make use of the new API.

@johnnesky johnnesky requested a review from a team as a code owner May 24, 2025 07:08
@johnnesky johnnesky requested a review from gonfunko May 24, 2025 07:08
@github-actions github-actions bot added PR: feature Adds a feature and removed PR: feature Adds a feature labels May 24, 2025
@johnnesky johnnesky merged commit ff2ec11 into google:develop May 27, 2025
12 checks passed
@johnnesky johnnesky deleted the nesky_context_paste branch May 27, 2025 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: feature Adds a feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pasting using the context menu opened via mouse should paste at the position of the mouse
2 participants
0