From 6e6b718283e28476c0908c5d7eaff6f43a92269e Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Fri, 29 Sep 2023 19:48:53 +0000 Subject: [PATCH 1/3] fix: pasting with nothing selected --- core/shortcut_items.ts | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/core/shortcut_items.ts b/core/shortcut_items.ts index 2e613307db2..96b56ad7fd3 100644 --- a/core/shortcut_items.ts +++ b/core/shortcut_items.ts @@ -12,6 +12,7 @@ import * as common from './common.js'; import {Gesture} from './gesture.js'; import {ICopyData, isCopyable} from './interfaces/i_copyable.js'; import {KeyboardShortcut, ShortcutRegistry} from './shortcut_registry.js'; +import { Rect } from './utils.js'; import {Coordinate} from './utils/coordinate.js'; import {KeyCodes} from './utils/keycodes.js'; import type {WorkspaceSvg} from './workspace_svg.js'; @@ -190,30 +191,16 @@ export function registerPaste() { }, callback() { if (!copyData || !copyCoords || !copyWorkspace) return false; - const { - left: viewportLeft, - top: viewportTop, - width: viewportWidth, - height: viewportHeight, - } = copyWorkspace.getMetricsManager().getViewMetrics(true); - const selected = common.getSelected() as BlockSvg; + const {left, top, width, height} = + copyWorkspace.getMetricsManager().getViewMetrics(true); + const viewportRect = new Rect(top, top + height, left, left + width) - // Pass the default copy coordinates when - // default location is inside viewport. - if ( - copyCoords.x >= viewportLeft && - copyCoords.x + selected.width <= viewportLeft + viewportWidth && - copyCoords.y >= viewportTop && - copyCoords.y + selected.height <= viewportTop + viewportHeight - ) { + if (viewportRect.contains(copyCoords.x, copyCoords.y)) { + // Pass the default copy coordinates when they are inside the viewport. return !!clipboard.paste(copyData, copyWorkspace, copyCoords); } else { - // Pass the center of the new viewport - // to paste the copied block - const centerCoords = new Coordinate( - viewportLeft + Math.trunc(viewportWidth / 2 - selected.width / 2), - viewportTop + Math.trunc(viewportHeight / 2 - selected.height / 2), - ); + // Otherwise paste in the middle of the viewport. + const centerCoords = new Coordinate(left + width / 2, top + height / 2); return !!clipboard.paste(copyData, copyWorkspace, centerCoords); } }, From 6d49e547890136d8d5b1c436d5c3bce2dc42971f Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Fri, 29 Sep 2023 19:50:12 +0000 Subject: [PATCH 2/3] fix: import --- core/shortcut_items.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/shortcut_items.ts b/core/shortcut_items.ts index 96b56ad7fd3..d234ebe240e 100644 --- a/core/shortcut_items.ts +++ b/core/shortcut_items.ts @@ -12,7 +12,7 @@ import * as common from './common.js'; import {Gesture} from './gesture.js'; import {ICopyData, isCopyable} from './interfaces/i_copyable.js'; import {KeyboardShortcut, ShortcutRegistry} from './shortcut_registry.js'; -import { Rect } from './utils.js'; +import {Rect} from './utils/rect.js'; import {Coordinate} from './utils/coordinate.js'; import {KeyCodes} from './utils/keycodes.js'; import type {WorkspaceSvg} from './workspace_svg.js'; From 6d7ec8f23a6112084277b5097e534e4ad170a36b Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Fri, 29 Sep 2023 19:56:41 +0000 Subject: [PATCH 3/3] chore: format --- core/shortcut_items.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/shortcut_items.ts b/core/shortcut_items.ts index d234ebe240e..31664848195 100644 --- a/core/shortcut_items.ts +++ b/core/shortcut_items.ts @@ -191,9 +191,10 @@ export function registerPaste() { }, callback() { if (!copyData || !copyCoords || !copyWorkspace) return false; - const {left, top, width, height} = - copyWorkspace.getMetricsManager().getViewMetrics(true); - const viewportRect = new Rect(top, top + height, left, left + width) + const {left, top, width, height} = copyWorkspace + .getMetricsManager() + .getViewMetrics(true); + const viewportRect = new Rect(top, top + height, left, left + width); if (viewportRect.contains(copyCoords.x, copyCoords.y)) { // Pass the default copy coordinates when they are inside the viewport.