-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathundo.ts
More file actions
46 lines (35 loc) · 878 Bytes
/
undo.ts
File metadata and controls
46 lines (35 loc) · 878 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
let undoStack: ImageState[];
let undoPosition: number;
function InitUndo()
{
// First image is created by the first CreateImage()
undoStack = [];
undoPosition = -1;
let saved = localStorage.getItem("undoMaxEntries");
settings.maxUndoEntries = saved == null ? 200 : parseInt(saved);
}
function RecordUndo()
{
if (undoPosition + 1 < undoStack.length)
undoStack = undoStack.slice(0, undoPosition + 1);
undoStack.push(ImageState.Get());
undoPosition++;
while (undoStack.length > settings.maxUndoEntries)
{
undoStack.shift();
undoPosition--;
}
SaveHistory();
}
function Undo()
{
if (undoPosition <= 0) return;
undoPosition--;
undoStack[undoPosition].Set();
}
function Redo()
{
if (undoPosition >= undoStack.length - 1) return;
undoPosition++;
undoStack[undoPosition].Set();
}