- address · parser — A1 ↔ 행열 · 낱말(편집기 색칠용 자리) · 엑셀 우선순위 나무(-2^2=4 · % · & · 비교) · 나무 → 글 - eval — 분수 풀이 · 오류 값 전파(왼쪽 먼저) · 형 바꾸기(빈 칸 · 수 글 · 참거짓) · 일반 형식 글 15 자리 · 무리수 15 자리 - graph — 의존 그래프 · 고친 칸에 딸린 칸만 재계산 · 순환 = 고리 칸마다 #CYCLE! + 까닭 - refshift — 행열 넣기 · 지우기 · 잘라 붙이기 · 시트 이름 · 시트 지우기 참조 옮김(지운 칸 #REF!) · 복사 상대 옮김 · 구글 R1C1 → A1 - commands · history · recalc — 명령마다 되돌림 짝 · 병합 규칙 · 서식 한 벌 표 · 묶음 원자 · Node 한 벌 풀이 - 시험 resources/tester/spreadsheet/test_spreadsheet_engine.py — 엑셀 규칙표 9 묶음 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TULoa94ZFL26KU6ZqVpjkF
39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
/* =============================================================================
|
|
* spreadsheet_history.ts (주인 A)
|
|
* 되돌리기 · 다시 — 명령과 되돌림 짝을 쌓음(메모리만 · 캐시에 안 넣음).
|
|
* undo() 는 되돌림 짝을 · redo() 는 원래 명령을 돌려줌 — 적용은 부른 쪽(`applyCommand`).
|
|
* ========================================================================== */
|
|
|
|
import type { Command, History } from "./spreadsheet_types";
|
|
|
|
/** `limit` = 쌓을 수(넘으면 오래된 것부터 버림) */
|
|
export function createHistory(limit = 100): History {
|
|
let done: [Command, Command][] = [];
|
|
let undone: [Command, Command][] = [];
|
|
return {
|
|
push(command, undo) {
|
|
done.push([command, undo]);
|
|
if (done.length > limit) done.shift();
|
|
undone = [];
|
|
},
|
|
undo() {
|
|
const pair = done.pop();
|
|
if (!pair) return null;
|
|
undone.push(pair);
|
|
return pair[1];
|
|
},
|
|
redo() {
|
|
const pair = undone.pop();
|
|
if (!pair) return null;
|
|
done.push(pair);
|
|
return pair[0];
|
|
},
|
|
canUndo: () => done.length > 0,
|
|
canRedo: () => undone.length > 0,
|
|
clear() {
|
|
done = [];
|
|
undone = [];
|
|
},
|
|
};
|
|
}
|