mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-10 12:01:36 +00:00
PageScene: ColorAction signals panel refresh on apply/revert
When the user undoes a color change while the Object Panel is open, the THREE.js material reverts correctly but the panel's local React `color` state stays at the redo value — the panel preview Button and the color input value disagree with the actual scene material. Root cause: the per-frame `getSelectedSum` check in renderSingleFrame pushes a fresh `objectPanel` slice to Zustand whenever transforms change, which re-fires the panel's useEffect and re-reads userData.color. Color changes don't move the sum, so the push never happens after a color undo/redo. Fix: ColorAction.apply/revert now calls `editor.selection.updateSelectedUI()` after the engine setColor. That pushes a new currentSceneObject reference into Zustand, the panel's [currentSceneObject] effect fires, and `setColor(editorEngine?.selected?.userData.color)` reads the freshly reverted value. Same pattern the lock/transform paths already use for UI sync.
This commit is contained in:
1 parent
e8db3f577a
commit
c6217eb88e
1 file changed
+9
@@ -4,6 +4,13 @@ import type { UndoableAction } from "../HistoryManager";
|
||||
// Records a color change. apply() and revert() both call
|
||||
// activeScene.setColor — the engine handles material magic. The action
|
||||
// captures the uuid + before/after hex pair at construction time.
|
||||
//
|
||||
// Each replay also fires SelectionBridge.updateSelectedUI() so the
|
||||
// Object Panel re-reads userData.color and refreshes its preview.
|
||||
// Without this, undo correctly reverts the THREE.js material but
|
||||
// ControlPanelSceneObject's local React state stays at the redo
|
||||
// value (the per-frame getSelectedSum check that picks up transform
|
||||
// changes doesn't notice color changes).
|
||||
export class ColorAction implements UndoableAction {
|
||||
readonly label = "Color";
|
||||
|
||||
@@ -16,9 +23,11 @@ export class ColorAction implements UndoableAction {
|
||||
|
||||
apply(): void {
|
||||
this.editor.activeScene.setColor(this.uuid, this.after);
|
||||
this.editor.selection.updateSelectedUI();
|
||||
}
|
||||
|
||||
revert(): void {
|
||||
this.editor.activeScene.setColor(this.uuid, this.before);
|
||||
this.editor.selection.updateSelectedUI();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user