Skip to content

Commit

Permalink
fix: update stroke wrong when redo
Browse files Browse the repository at this point in the history
  • Loading branch information
F-star committed Mar 5, 2024
1 parent a0c75aa commit 29afd94
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions packages/suika/src/components/Cards/FillCard/FillCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ export const FillCard: FC = () => {
const pushToHistory = (
cmdDesc: string,
selectedElements: Graph[],
newStroke: ITexture[],
newPaints: ITexture[],
) => {
if (!editor) return;

editor.commandManager.pushCommand(
new SetGraphsAttrsCmd(
cmdDesc,
selectedElements,
{ fill: newStroke },
{ fill: newPaints },
// prev value
selectedElements.map((_, i) => ({
fill: cloneDeep(prevFills.current[i]),
Expand Down
14 changes: 9 additions & 5 deletions packages/suika/src/components/Cards/StrokeCard/StrokeCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ export const StrokeCard: FC = () => {

useEffect(() => {
if (editor) {
prevStrokes.current = editor.selectedElements
.getItems()
.map((el) => cloneDeep(el.attrs.stroke ?? []));
const updatePrevStroke = (els: Graph[]) => {
prevStrokes.current = els.map((el) => cloneDeep(el.attrs.stroke ?? []));
};

const updateInfo = () => {
const selectedElements = editor.selectedElements.getItems();
Expand Down Expand Up @@ -59,11 +59,15 @@ export const StrokeCard: FC = () => {
}
};

updateInfo(); // init
// init
updateInfo();
updatePrevStroke(editor.selectedElements.getItems());

editor.sceneGraph.on('render', updateInfo);
editor.selectedElements.on('itemsChange', updatePrevStroke);
return () => {
editor.sceneGraph.off('render', updateInfo);
editor.selectedElements.off('itemsChange', updatePrevStroke);
};
}
}, [editor]);
Expand Down Expand Up @@ -162,7 +166,7 @@ export const StrokeCard: FC = () => {
);

prevStrokes.current = selectedElements.map((el) =>
cloneDeep(el.attrs.fill ?? []),
cloneDeep(el.attrs.stroke ?? []),
);
};

Expand Down

0 comments on commit 29afd94

Please sign in to comment.