Skip to content

Commit ff2ec11

Browse files
authored
feat: Paste where context menu was opened (#9093)
1 parent cc9384a commit ff2ec11

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

core/shortcut_items.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {KeyboardShortcut, ShortcutRegistry} from './shortcut_registry.js';
1717
import {Coordinate} from './utils/coordinate.js';
1818
import {KeyCodes} from './utils/keycodes.js';
1919
import {Rect} from './utils/rect.js';
20+
import * as svgMath from './utils/svg_math.js';
2021
import {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

Comments
 (0)