Order based on fractional index in history action

This commit is contained in:
Marcel Mraz 2023-12-11 12:15:38 +01:00
parent 260706c42f
commit d872adf593
2 changed files with 6 additions and 4 deletions

View File

@ -9,6 +9,7 @@ import { arrayToMap } from "../utils";
import { isWindows } from "../constants"; import { isWindows } from "../constants";
import { ExcalidrawElement } from "../element/types"; import { ExcalidrawElement } from "../element/types";
import { fixBindingsAfterDeletion } from "../element/binding"; import { fixBindingsAfterDeletion } from "../element/binding";
import { orderByFractionalIndex } from "../fractionalIndex";
const writeData = ( const writeData = (
appState: Readonly<AppState>, appState: Readonly<AppState>,
@ -28,7 +29,9 @@ const writeData = (
// TODO_UNDO: worth detecting z-index deltas or do we just order based on fractional indices? // TODO_UNDO: worth detecting z-index deltas or do we just order based on fractional indices?
const [nextElementsMap, nextAppState] = result; const [nextElementsMap, nextAppState] = result;
const nextElements = Array.from(nextElementsMap.values()); const nextElements = orderByFractionalIndex(
Array.from(nextElementsMap.values()),
);
// TODO_UNDO: these are all deleted elements, but ideally we should get just those that were delted at this moment // TODO_UNDO: these are all deleted elements, but ideally we should get just those that were delted at this moment
const deletedElements = nextElements.filter((element) => element.isDeleted); const deletedElements = nextElements.filter((element) => element.isDeleted);
@ -37,7 +40,7 @@ const writeData = (
return { return {
appState: nextAppState, appState: nextAppState,
elements: Array.from(nextElementsMap.values()), elements: nextElements,
storeAction: StoreAction.UPDATE, storeAction: StoreAction.UPDATE,
}; };
} }

View File

@ -40,8 +40,7 @@ import {
import { createRedoAction, createUndoAction } from "../actions/actionHistory"; import { createRedoAction, createUndoAction } from "../actions/actionHistory";
import { ActionManager } from "../actions/manager"; import { ActionManager } from "../actions/manager";
import { actions } from "../actions/register"; import { actions } from "../actions/register";
import { Action, ActionResult } from "../actions/types"; import { Action, ActionResult, StoreAction } from "../actions/types";
import { ActionResult, StoreAction } from "../actions/types";
import { trackEvent } from "../analytics"; import { trackEvent } from "../analytics";
import { import {
getDefaultAppState, getDefaultAppState,