From c218b9c07ea2c33bf693bb32b7f0b0c4a345f9c3 Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Tue, 1 Aug 2023 20:58:52 +0000 Subject: [PATCH] chore: format --- core/clipboard.ts | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/core/clipboard.ts b/core/clipboard.ts index 281f1bca25c..1e6ec053310 100644 --- a/core/clipboard.ts +++ b/core/clipboard.ts @@ -40,8 +40,11 @@ function copyInternal(toCopy: ICopyable): T | null { } /** - * Paste a block or workspace comment on to the main workspace. + * Paste a pasteable element into the workspace. * + * @param copyData The data to paste into the workspace. + * @param workspace The workspace to paste the data into. + * @param coordinate The location to paste the thing at. * @returns The pasted thing if the paste was successful, null otherwise. */ export function paste( @@ -49,7 +52,23 @@ export function paste( workspace: WorkspaceSvg, coordinate?: Coordinate, ): ICopyable | null; + +/** + * Pastes the last copied ICopyable into the workspace. + * + * @returns the pasted thing if the paste was successful, null otherwise. + */ export function paste(): ICopyable | null; + +/** + * Pastes the given data into the workspace, or the last copied ICopyable if + * no data is passed. + * + * @param copyData The data to paste into the workspace. + * @param workspace The workspace to paste the data into. + * @param coordinate The location to paste the thing at. + * @returns The pasted thing if the paste was successful, null otherwise. + */ export function paste( copyData?: T, workspace?: WorkspaceSvg, @@ -62,17 +81,23 @@ export function paste( return pasteFromData(copyData, workspace, coordinate); } +/** + * Paste a pasteable element into the workspace. + * + * @param copyData The data to paste into the workspace. + * @param workspace The workspace to paste the data into. + * @param coordinate The location to paste the thing at. + * @returns The pasted thing if the paste was successful, null otherwise. + */ function pasteFromData( copyData: T, workspace: WorkspaceSvg, coordinate?: Coordinate, ): ICopyable | null { workspace = workspace.getRootWorkspace() ?? workspace; - return ( - globalRegistry - .getObject(globalRegistry.Type.PASTER, copyData.paster, false) - ?.paste(copyData, workspace, coordinate) ?? null - ) as ICopyable | null; + return (globalRegistry + .getObject(globalRegistry.Type.PASTER, copyData.paster, false) + ?.paste(copyData, workspace, coordinate) ?? null) as ICopyable | null; } /** @@ -104,8 +129,8 @@ function duplicateInternal< // I hate side effects. stashedCopyData = oldCopyData; - stashedWorkspace = oldWorkspace - + stashedWorkspace = oldWorkspace; + if (!data) return null; return paste(data, toDuplicate.workspace) as T; }