|
1 | 1 | -- make sure events dont get called more than once in a row! |
2 | 2 |
|
3 | 3 | -- action list |
4 | | -local actionList = {} |
5 | | -local index = 0 |
6 | | - |
7 | | --- action states |
8 | | -local justUndid = false |
9 | | -local justRedid = false |
10 | | -local justAdded = false |
| 4 | +actionList = {} |
| 5 | +currentActionIndex = 0 |
11 | 6 |
|
12 | 7 | -- ADD |
13 | 8 | function insertAction(action) -- messes shit up |
14 | 9 | -- insert action into list, removing any actions that might come after it |
15 | | - if (not justUndid) then |
16 | | - removeActionsAfterIndex(index) |
17 | | - index = index + 1 |
18 | | - else |
19 | | - removeActionsAfterIndex(index-1) |
20 | | - end |
21 | | - table.insert(actionList, index, action) |
22 | | - -- update action state flags |
23 | | - justUndid = false |
24 | | - justRedid = false |
25 | | - justAdded = true |
| 10 | + while #actionList > currentActionIndex do |
| 11 | + table.remove(actionList, #actionList) |
| 12 | + end |
| 13 | + currentActionIndex = currentActionIndex + 1 |
| 14 | + table.insert(actionList, currentActionIndex, action) |
26 | 15 | end |
27 | 16 |
|
28 | 17 | -- create |
@@ -67,56 +56,20 @@ function addActionElementPropertiesChange(oldProperties, newProperties) |
67 | 56 | end |
68 | 57 | addEventHandler("onElementPropertiesChange_undoredo", root, addActionElementPropertiesChange) |
69 | 58 |
|
70 | | --- removes lowIndex?? |
71 | | -function removeActionsAfterIndex(lowIndex) |
72 | | - local curIndex = #actionList |
73 | | - while (curIndex > lowIndex) do |
74 | | - actionList[curIndex]:destructor() |
75 | | - table.remove(actionList, curIndex) |
76 | | - curIndex = curIndex - 1 |
77 | | - end |
78 | | -end |
79 | | - |
80 | 59 | function undo() |
81 | | - if (justUndid) then |
82 | | - if (index > 1) then |
83 | | - index = index - 1 |
84 | | - actionList[index]:performUndo() |
85 | | - -- update action state flags |
86 | | - justUndid = true |
87 | | - justRedid = false |
88 | | - justAdded = false |
89 | | - end |
90 | | - elseif (justRedid or justAdded) then |
91 | | - actionList[index]:performUndo() |
92 | | - -- update action state flags |
93 | | - justUndid = true |
94 | | - justRedid = false |
95 | | - justAdded = false |
96 | | - end |
| 60 | + if currentActionIndex > 0 then |
| 61 | + actionList[currentActionIndex]:performUndo() |
| 62 | + currentActionIndex = currentActionIndex - 1 |
| 63 | + end |
97 | 64 | end |
98 | 65 | addCommandHandler("undo", undo) |
99 | 66 | addEventHandler("doUndo", root, undo) |
100 | 67 |
|
101 | 68 | function redo() |
102 | | - if (not justAdded) then |
103 | | - if (justRedid) then |
104 | | - if (actionList[index+1]) then |
105 | | - index = index + 1 |
106 | | - actionList[index]:performRedo() |
107 | | - -- update action state flags |
108 | | - justUndid = false |
109 | | - justRedid = true |
110 | | - justAdded = false |
111 | | - end |
112 | | - elseif (justUndid) then |
113 | | - actionList[index]:performRedo() |
114 | | - -- update action state flags |
115 | | - justUndid = false |
116 | | - justRedid = true |
117 | | - justAdded = false |
118 | | - end |
119 | | - end |
| 69 | + if currentActionIndex < #actionList then |
| 70 | + currentActionIndex = currentActionIndex + 1 |
| 71 | + actionList[currentActionIndex]:performRedo() |
| 72 | + end |
120 | 73 | end |
121 | 74 | addCommandHandler("redo", redo) |
122 | 75 | addEventHandler("doRedo", root, redo) |
0 commit comments