Skip to content

Commit

Permalink
chore: format
Browse files Browse the repository at this point in the history
  • Loading branch information
BeksOmega committed Aug 1, 2023
1 parent a12ed49 commit c218b9c
Showing 1 changed file with 33 additions and 8 deletions.
41 changes: 33 additions & 8 deletions core/clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,35 @@ function copyInternal<T extends ICopyData>(toCopy: ICopyable<T>): 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<T extends ICopyData>(
copyData: T,
workspace: WorkspaceSvg,
coordinate?: Coordinate,
): ICopyable<T> | null;

/**
* Pastes the last copied ICopyable into the workspace.
*
* @returns the pasted thing if the paste was successful, null otherwise.
*/
export function paste(): ICopyable<ICopyData> | 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<T extends ICopyData>(
copyData?: T,
workspace?: WorkspaceSvg,
Expand All @@ -62,17 +81,23 @@ export function paste<T extends ICopyData>(
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<T extends ICopyData>(
copyData: T,
workspace: WorkspaceSvg,
coordinate?: Coordinate,
): ICopyable<T> | null {
workspace = workspace.getRootWorkspace() ?? workspace;
return (
globalRegistry
.getObject(globalRegistry.Type.PASTER, copyData.paster, false)
?.paste(copyData, workspace, coordinate) ?? null
) as ICopyable<T> | null;
return (globalRegistry
.getObject(globalRegistry.Type.PASTER, copyData.paster, false)
?.paste(copyData, workspace, coordinate) ?? null) as ICopyable<T> | null;
}

/**
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit c218b9c

Please sign in to comment.