修正清空编辑器历史边界

清空编辑器时重置撤销与重做栈

补充清空操作不会进入历史的测试
This commit is contained in:
2026-09-03 11:06:47 +08:00
parent e379459820
commit 0544e78996
2 changed files with 13 additions and 2 deletions
@@ -1520,9 +1520,10 @@ export function useUiEditorState(initialState: State = EMPTY_UI_EDITOR_STATE) {
const clearState = useCallback((): UiEditorOperationResult => {
const blocked = guard();
if (blocked) return blocked;
commit(cloneState(EMPTY_UI_EDITOR_STATE));
resetHistory();
applyState(cloneState(EMPTY_UI_EDITOR_STATE));
return { ok: true, value: undefined };
}, [commit, guard]);
}, [applyState, guard, resetHistory]);
const replaceState = useCallback(
(nextState: State, options: UiEditorReplaceStateOptions = {}) => {
@@ -666,6 +666,16 @@ describe('useUiEditorState', () => {
canUndo: false,
canRedo: false,
});
act(() => {
result.current.setImageName('page', '清空前');
result.current.clearState();
});
expect(result.current.state).toEqual(EMPTY_UI_EDITOR_STATE);
expect(result.current.historyState).toEqual({
canUndo: false,
canRedo: false,
});
});
it('groups multiple replacements into one history transaction and rolls back failures', async () => {