Skip to content

Commit

Permalink
fix: update fill 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 a060da7 commit a0c75aa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
4 changes: 3 additions & 1 deletion packages/core/src/commands/set_elements_attrs.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { cloneDeep } from '@suika/common';

import { Graph, IPathItem } from '../graphs';
import { ITexture } from '../texture';
import { ICommand } from './type';
Expand Down Expand Up @@ -38,7 +40,7 @@ export class SetGraphsAttrsCmd implements ICommand {
if (Array.isArray(attrs)) {
elements[i].updateAttrs(attrs[i]);
} else {
elements[i].updateAttrs(attrs);
elements[i].updateAttrs(cloneDeep(attrs));
}
}
}
Expand Down
13 changes: 8 additions & 5 deletions packages/suika/src/components/Cards/FillCard/FillCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,9 @@ export const FillCard: FC = () => {

useEffect(() => {
if (editor) {
prevFills.current = editor.selectedElements
.getItems()
.map((el) => cloneDeep(el.attrs.fill ?? []));

const updatePrevFill = (els: Graph[]) => {
prevFills.current = els.map((el) => cloneDeep(el.attrs.fill ?? []));
};
const updateInfo = () => {
const selectedElements = editor.selectedElements.getItems();
if (selectedElements.length > 0) {
Expand All @@ -115,11 +114,15 @@ export const FillCard: FC = () => {
}
};

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

editor.sceneGraph.on('render', updateInfo);
editor.selectedElements.on('itemsChange', updatePrevFill);
return () => {
editor.sceneGraph.off('render', updateInfo);
editor.selectedElements.off('itemsChange', updatePrevFill);
};
}
}, [editor]);
Expand Down

0 comments on commit a0c75aa

Please sign in to comment.