feat: fractional indexing (#7359)
* Introducing fractional indices as part of `element.index` * Ensuring invalid fractional indices are always synchronized with the array order * Simplifying reconciliation based on the fractional indices * Moving reconciliation inside the `@excalidraw/excalidraw` package --------- Co-authored-by: Marcel Mraz <marcel@excalidraw.com> Co-authored-by: dwelle <5153846+dwelle@users.noreply.github.com>
This commit is contained in:
co-authored by
Marcel Mraz
dwelle
parent
bbdcd30a73
commit
32df5502ae
@@ -27,6 +27,7 @@ import {
|
||||
removeElementsFromFrame,
|
||||
replaceAllElementsInFrame,
|
||||
} from "../frame";
|
||||
import { syncMovedIndices } from "../fractionalIndex";
|
||||
|
||||
const allElementsInSameGroup = (elements: readonly ExcalidrawElement[]) => {
|
||||
if (elements.length >= 2) {
|
||||
@@ -140,11 +141,12 @@ export const actionGroup = register({
|
||||
.filter(
|
||||
(updatedElement) => !isElementInGroup(updatedElement, newGroupId),
|
||||
);
|
||||
nextElements = [
|
||||
const reorderedElements = [
|
||||
...elementsBeforeGroup,
|
||||
...elementsInGroup,
|
||||
...elementsAfterGroup,
|
||||
];
|
||||
syncMovedIndices(reorderedElements, arrayToMap(elementsInGroup));
|
||||
|
||||
return {
|
||||
appState: {
|
||||
@@ -155,7 +157,7 @@ export const actionGroup = register({
|
||||
getNonDeletedElements(nextElements),
|
||||
),
|
||||
},
|
||||
elements: nextElements,
|
||||
elements: reorderedElements,
|
||||
commitToHistory: true,
|
||||
};
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user