normalize before replacing

This commit is contained in:
Ryan Di
2023-12-01 15:58:49 +08:00
parent 00ffa08e28
commit 1e132e33ae
3 changed files with 93 additions and 108 deletions

View File

@@ -11,6 +11,7 @@ import { getSelectedElements } from "./selection";
import { AppState } from "../types";
import { Assert, SameType } from "../utility-types";
import { randomInteger } from "../random";
import { normalizeFractionalIndexing } from "../zindex";
type ElementIdKey = InstanceType<typeof LinearElementEditor>["elementId"];
type ElementKey = ExcalidrawElement | ElementIdKey;
@@ -231,10 +232,12 @@ class Scene {
nextElements: readonly ExcalidrawElement[],
mapElementIds = true,
) {
this.elements = nextElements;
const _nextElements = normalizeFractionalIndexing(nextElements);
this.elements = _nextElements;
const nextFrameLikes: ExcalidrawFrameLikeElement[] = [];
this.elementsMap.clear();
nextElements.forEach((element) => {
_nextElements.forEach((element) => {
if (isFrameLikeElement(element)) {
nextFrameLikes.push(element);
}