test(workbench): lock cross-domain edit history

This commit is contained in:
que01 committed 2026-09-02 16:57:36 +08:00
1 parent bb6c51c489
commit 2fb9db65e5
3 files changed
+78 -24

No files matched your search

+9 -24
View File
@@ -33,6 +33,7 @@ import {
import { previewArrowFeatures } from './edit/arrow-preview';
import { rendersSame } from './edit/parameter';
import { PreviewRequester, type PreviewDraft } from './edit/preview-request';
import { clearEditHistory, recordEdit, takeRedoDomain, takeUndoDomain, type EditHistory } from './edit/edit-history';
import {
anchorSnapshotFor,
constraintValueFor,
@@ -80,12 +81,10 @@ function App() {
const [status, setStatus] = useState('正在加载工作台...');
const [filter, setFilter] = useState<'all' | 'candidates' | 'other'>('all');
const [marking, setMarking] = useState<Record<string, unknown> | null>(null);
const editOrderRef = useRef<Array<'session' | 'signal'>>([]);
const redoOrderRef = useRef<Array<'session' | 'signal'>>([]);
const editHistoryRef = useRef<EditHistory>({ undo: [], redo: [] });
const recordSignalEdit = useMemo(
() => () => {
editOrderRef.current.push('signal');
redoOrderRef.current = [];
recordEdit(editHistoryRef.current, 'signal');
},
[],
);
@@ -402,8 +401,7 @@ function App() {
if (!draft || !session) return;
requester?.flush(draft);
session.commit(draft.constraints ?? [], constraintIds, gestureIdentity());
editOrderRef.current.push('session');
redoOrderRef.current = [];
recordEdit(editHistoryRef.current, 'session');
gesture.current = null;
touch();
};
@@ -482,11 +480,7 @@ function App() {
);
};
const undoEdit = () => {
const domain = editOrderRef.current.at(-1);
if (domain === 'signal') {
editOrderRef.current.pop();
redoOrderRef.current.push('signal');
}
const domain = takeUndoDomain(editHistoryRef.current);
// A saved gesture cannot be un-applied — persisted history is append-only — so
// it is reversed by an inverse operation, which needs its own identity.
if (domain === 'signal' && signalUndoRef.current.length) {
@@ -507,10 +501,7 @@ function App() {
setSignalDirty(true);
return;
}
if (domain === 'session') {
editOrderRef.current.pop();
redoOrderRef.current.push('session');
}
if (domain !== 'session') return;
const reversed = session?.undo({
operationId: `operation:undo:${Date.now()}`,
createdAt: new Date().toISOString(),
@@ -520,10 +511,8 @@ function App() {
previewSession();
};
const redoEdit = () => {
const domain = redoOrderRef.current.at(-1);
const domain = takeRedoDomain(editHistoryRef.current);
if (domain === 'signal' && signalRedoRef.current.length) {
redoOrderRef.current.pop();
editOrderRef.current.push('signal');
const next = signalRedoRef.current.pop()!;
signalUndoRef.current.push(state?.trafficSignals.assemblies.features || []);
setState((current) =>
@@ -541,10 +530,7 @@ function App() {
setSignalDirty(true);
return;
}
if (domain === 'session') {
redoOrderRef.current.pop();
editOrderRef.current.push('session');
}
if (domain !== 'session') return;
if (!session?.redo()) return;
touch();
previewSession();
@@ -568,8 +554,7 @@ function App() {
signalDraftRef.current = null;
signalUndoRef.current = [];
signalRedoRef.current = [];
editOrderRef.current = [];
redoOrderRef.current = [];
clearEditHistory(editHistoryRef.current);
setSignalDirty(false);
clearStaged();
gesture.current = null;