feat(508-3a CAD 레이어 합치기 되돌리기): LAYMRG · LAYDEL 뒤 Ctrl+Z 한 번에 도형 레이어 · 레이어 목록 · 현재 층이 함께 돌아오고 Ctrl+Y 도 짝 · 되돌리기 단계에 도면층 전후 담음(state attachLayerChangeToUndo) · vitest layer-tools.test · 요구 325-1

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-22 17:08:49 +09:00
co-authored by Claude Sonnet 5.5
parent 80020c26c5
commit 18fa773a2c
4 changed files with 152 additions and 13 deletions
+29 -1
View File
@@ -12,7 +12,12 @@ import {
import type { ScreenCanvasDrawController } from './drawControllers/screenCanvas.drawController';
import type { Entity } from './entities/Entity';
import { bumpSceneVersion } from './helpers/scene-version';
import { StateVariable, type UndoState, createStack } from './helpers/undo-stack';
import {
type LayerSnapshot,
StateVariable,
type UndoState,
createStack,
} from './helpers/undo-stack';
import type { InputController } from './inputController/input-controller.ts'; // state variables
import { type PromptMeta, renderPrompt, rememberPoint, resolvePrompt } from './commands/prompt';
@@ -626,20 +631,43 @@ export function resetUndoBaseline() {
drawingDirty = false;
}
export const getLayerSnapshot = (): LayerSnapshot => ({ layers, activeLayerId });
/**
* 방금 쌓은 객체 되돌리기 단계에 도면층 전 · 후를 붙인다(LAYMRG · LAYDEL) —
* Ctrl+Z 한 번에 객체와 도면층이 함께 돌아오고 Ctrl+Y 도 짝으로 간다.
* 맨 위 단계가 지금 객체 목록이 아니면(쌓이지 않음) 붙이지 않는다.
*/
export function attachLayerChangeToUndo(before: LayerSnapshot, after: LayerSnapshot) {
const top = undoStack.peek();
if (top?.variable === StateVariable.entities && top.value === entities) {
top.layerChange = { before, after };
}
}
function applyLayerSnapshot(snapshot: LayerSnapshot) {
setLayers(snapshot.layers);
setActiveLayerId(snapshot.activeLayerId);
}
export function undo() {
const undone = undoStack.peek();
const undoState = undoStack.undo();
if (!undoState) return;
updateStates(undoState);
if (undone !== undoState && undone?.layerChange) applyLayerSnapshot(undone.layerChange.before);
drawingDirty = true; // 되돌려도 저장본과는 다를 수 있다 — 미저장 경고 대상이다
notifyWindow(HtmlEvent.DRAWING_CHANGED);
}
export function redo() {
const current = undoStack.peek();
const redoState = undoStack.redo();
if (!redoState) return;
updateStates(redoState);
if (current !== redoState && redoState.layerChange) applyLayerSnapshot(redoState.layerChange.after);
drawingDirty = true;
notifyWindow(HtmlEvent.DRAWING_CHANGED);
}