Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions web-frontend/src/pages/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1340,8 +1340,17 @@ export default function Editor() {
}
}

// Single item update
editorStore.updateItem(projectId, itemId, snappedUpdates);
// Skip history entry for image metadata sync
const isMetadataSync =
"naturalWidth" in snappedUpdates ||
"naturalHeight" in snappedUpdates;

editorStore.updateItem(
projectId,
itemId,
snappedUpdates,
!isMetadataSync,
);

// If the component moved, reset connection waypoints so routing recalculates
if (updates.x !== undefined || updates.y !== undefined) {
Expand Down
60 changes: 35 additions & 25 deletions web-frontend/src/store/useEditorStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ interface EditorStore {
) => CanvasItem | undefined;

updateItem: (
editorId: string,
itemId: number,
patch: Partial<CanvasItem>,
) => void;
editorId: string,
itemId: number,
patch: Partial<CanvasItem>,
recordHistory?: boolean,
) => void;

deleteItem: (editorId: string, itemId: number) => void;

Expand Down Expand Up @@ -284,31 +285,40 @@ export const useEditorStore = create<EditorStore>((set, get) => ({
return newItem;
},

updateItem: (editorId, itemId, patch) => {
set((s) => {
const ed = s.editors[editorId];
updateItem: (
editorId,
itemId,
patch,
recordHistory = true,
) => {
set((s) => {
const ed = s.editors[editorId];

if (!ed) return s;
if (!ed) return s;

// --- RECORD HISTORY ---
const snapshot = createSnapshot(ed);
// ----------------------
const snapshot = recordHistory
? createSnapshot(ed)
: null;

return {
editors: {
...s.editors,
[editorId]: {
...ed,
items: ed.items.map((it) =>
it.id === itemId ? { ...it, ...patch } : it,
),
past: [...ed.past, snapshot],
future: [],
},
return {
editors: {
...s.editors,
[editorId]: {
...ed,
items: ed.items.map((it) =>
it.id === itemId ? { ...it, ...patch } : it,
),
past: snapshot
? [...ed.past, snapshot]
: ed.past,
future: recordHistory
? []
: ed.future,
},
};
});
},
},
};
});
},

deleteItem: (editorId, itemId) => {
set((s) => {
Expand Down
Loading