mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Insert after duplication
This commit is contained in:
parent
c4767a3144
commit
9a20ac3b8d
1 changed files with 23 additions and 2 deletions
|
@ -3,9 +3,14 @@ import { getNewGroupIdsForDuplication } from "../groups";
|
|||
import { randomId, randomInteger } from "../random";
|
||||
import type { AppState } from "../types";
|
||||
import type { Mutable } from "../utility-types";
|
||||
import { arrayToMap, getUpdatedTimestamp, isTestEnv } from "../utils";
|
||||
import {
|
||||
arrayToMap,
|
||||
castArray,
|
||||
getUpdatedTimestamp,
|
||||
invariant,
|
||||
isTestEnv,
|
||||
} from "../utils";
|
||||
import { bumpVersion } from "./mutateElement";
|
||||
import { isArrowElement } from "./typeChecks";
|
||||
import type { ExcalidrawElement, GroupId } from "./types";
|
||||
|
||||
/**
|
||||
|
@ -176,12 +181,28 @@ export const duplicateElements = (
|
|||
clonedElement.frameId = maybeGetNewIdFor(clonedElement.frameId);
|
||||
}
|
||||
|
||||
insertAfterIndex();
|
||||
|
||||
clonedElements.push(clonedElement);
|
||||
}
|
||||
|
||||
return clonedElements;
|
||||
};
|
||||
|
||||
const insertAfterIndex = (
|
||||
elementsWithClones: ExcalidrawElement[],
|
||||
index: number,
|
||||
elements: ExcalidrawElement | null | ExcalidrawElement[],
|
||||
) => {
|
||||
invariant(index !== -1, "targetIndex === -1 ");
|
||||
|
||||
if (!Array.isArray(elements) && !elements) {
|
||||
return;
|
||||
}
|
||||
|
||||
return elementsWithClones.splice(index + 1, 0, ...castArray(elements));
|
||||
};
|
||||
|
||||
// Simplified deep clone for the purpose of cloning ExcalidrawElement.
|
||||
//
|
||||
// Only clones plain objects and arrays. Doesn't clone Date, RegExp, Map, Set,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue