@@ -17,6 +17,7 @@ import {KeyboardShortcut, ShortcutRegistry} from './shortcut_registry.js';
1717import {Coordinate} from './utils/coordinate.js';
1818import {KeyCodes} from './utils/keycodes.js';
1919import {Rect} from './utils/rect.js';
20+ import * as svgMath from './utils/svg_math.js';
2021import {WorkspaceSvg} from './workspace_svg.js';
2122
2223/**
@@ -212,8 +213,22 @@ export function registerPaste() {
212213 preconditionFn(workspace) {
213214 return !workspace.isReadOnly() && !Gesture.inProgress();
214215 },
215- callback() {
216+ callback(workspace: WorkspaceSvg, e: Event ) {
216217 if (!copyData || !copyWorkspace) return false;
218+
219+ if (e instanceof PointerEvent) {
220+ // The event that triggers a shortcut would conventionally be a KeyboardEvent.
221+ // However, it may be a PointerEvent if a context menu item was used as a
222+ // wrapper for this callback, in which case the new block(s) should be pasted
223+ // at the mouse coordinates where the menu was opened, and this PointerEvent
224+ // is where the menu was opened.
225+ const mouseCoords = svgMath.screenToWsCoordinates(
226+ copyWorkspace,
227+ new Coordinate(e.clientX, e.clientY),
228+ );
229+ return !!clipboard.paste(copyData, copyWorkspace, mouseCoords);
230+ }
231+
217232 if (!copyCoords) {
218233 // If we don't have location data about the original copyable, let the
219234 // paster determine position.
0 commit comments