fix fractional indices on duplication

mrazator/test-fractional-index-and-granular-history
Ryan Di 1 year ago
parent 7dfba985f9
commit 4f218856c3

@ -31,6 +31,7 @@ import {
excludeElementsInFramesFromSelection, excludeElementsInFramesFromSelection,
getSelectedElements, getSelectedElements,
} from "../scene/selection"; } from "../scene/selection";
import { fixFractionalIndices } from "../fractionalIndex";
export const actionDuplicateSelection = register({ export const actionDuplicateSelection = register({
name: "duplicateSelection", name: "duplicateSelection",
@ -85,6 +86,7 @@ const duplicateElements = (
const newElements: ExcalidrawElement[] = []; const newElements: ExcalidrawElement[] = [];
const oldElements: ExcalidrawElement[] = []; const oldElements: ExcalidrawElement[] = [];
const oldIdToDuplicatedId = new Map(); const oldIdToDuplicatedId = new Map();
const duplicatedElementsMap = new Map<string, ExcalidrawElement>();
const duplicateAndOffsetElement = (element: ExcalidrawElement) => { const duplicateAndOffsetElement = (element: ExcalidrawElement) => {
const newElement = duplicateElement( const newElement = duplicateElement(
@ -96,6 +98,7 @@ const duplicateElements = (
y: element.y + GRID_SIZE / 2, y: element.y + GRID_SIZE / 2,
}, },
); );
duplicatedElementsMap.set(newElement.id, newElement);
oldIdToDuplicatedId.set(element.id, newElement.id); oldIdToDuplicatedId.set(element.id, newElement.id);
oldElements.push(element); oldElements.push(element);
newElements.push(newElement); newElements.push(newElement);
@ -234,7 +237,10 @@ const duplicateElements = (
// step (3) // step (3)
const finalElements = finalElementsReversed.reverse(); const finalElements = fixFractionalIndices(
finalElementsReversed.reverse(),
duplicatedElementsMap,
);
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------

@ -399,6 +399,7 @@ import { COLOR_PALETTE } from "../colors";
import { ElementCanvasButton } from "./MagicButton"; import { ElementCanvasButton } from "./MagicButton";
import { MagicIcon, copyIcon, fullscreenIcon } from "./icons"; import { MagicIcon, copyIcon, fullscreenIcon } from "./icons";
import { EditorLocalStorage } from "../data/EditorLocalStorage"; import { EditorLocalStorage } from "../data/EditorLocalStorage";
import { fixFractionalIndices } from "../fractionalIndex";
const AppContext = React.createContext<AppClassProperties>(null!); const AppContext = React.createContext<AppClassProperties>(null!);
const AppPropsContext = React.createContext<AppProps>(null!); const AppPropsContext = React.createContext<AppProps>(null!);
@ -6845,6 +6846,7 @@ class App extends React.Component<AppProps, AppState> {
}) })
.map((element) => element.id), .map((element) => element.id),
); );
const duplicatedElementsMap = new Map<string, ExcalidrawElement>();
const elements = this.scene.getElementsIncludingDeleted(); const elements = this.scene.getElementsIncludingDeleted();
@ -6861,6 +6863,10 @@ class App extends React.Component<AppProps, AppState> {
groupIdMap, groupIdMap,
element, element,
); );
duplicatedElementsMap.set(
duplicatedElement.id,
duplicatedElement,
);
const origElement = pointerDownState.originalElements.get( const origElement = pointerDownState.originalElements.get(
element.id, element.id,
)!; )!;
@ -6883,7 +6889,10 @@ class App extends React.Component<AppProps, AppState> {
nextElements.push(element); nextElements.push(element);
} }
} }
const nextSceneElements = [...nextElements, ...elementsToAppend]; const nextSceneElements = fixFractionalIndices(
[...nextElements, ...elementsToAppend],
duplicatedElementsMap,
);
bindTextToShapeAfterDuplication( bindTextToShapeAfterDuplication(
nextElements, nextElements,
elementsToAppend, elementsToAppend,

Loading…
Cancel
Save