aboutsummaryrefslogtreecommitdiffstats
path: root/macros/garret.dupe-and-comment.lua
diff options
context:
space:
mode:
authorgarret <garret@airmail.cc>2023-01-15 01:19:53 +0000
committergarret <garret@airmail.cc>2023-01-15 13:26:14 +0000
commit5459e401b33de9b385af48f870e6ff4fe45c4c8b (patch)
tree014fb845f13f65eb4709a94edc9600da91c13303 /macros/garret.dupe-and-comment.lua
parent96bd8086c75576cfd77d83e6122428490869740b (diff)
downloadaegisub-scripts-5459e401b33de9b385af48f870e6ff4fe45c4c8b.tar.gz
aegisub-scripts-5459e401b33de9b385af48f870e6ff4fe45c4c8b.tar.bz2
aegisub-scripts-5459e401b33de9b385af48f870e6ff4fe45c4c8b.zip
dupe and comment: add notes about what's going on in undo function
not as thorough as `do` because most of `undo` is pretty clear on its own, and all of the "magic" bits have been explained in `do`. The only difference is that here it's the other way round.
Diffstat (limited to 'macros/garret.dupe-and-comment.lua')
-rw-r--r--macros/garret.dupe-and-comment.lua14
1 files changed, 11 insertions, 3 deletions
diff --git a/macros/garret.dupe-and-comment.lua b/macros/garret.dupe-and-comment.lua
index f819d40..f736df9 100644
--- a/macros/garret.dupe-and-comment.lua
+++ b/macros/garret.dupe-and-comment.lua
@@ -35,14 +35,22 @@ end
local function undo(subs, sel, act)
for i=#sel,1,-1 do
local edit=subs[sel[i]]
- if not (sel[i] + 1 > #subs) then
+ if not (sel[i] + 1 > #subs) then -- preventing out-of-range errors
local original=subs[sel[i]+1]
+
if edit.comment == false and original.comment == true then
original.comment = false
subs[sel[i]+1] = original
subs.delete(sel[i])
- for j=i+1,#sel do sel[j] = sel[j] - 1 end
- if act > sel[i] then act = act - 1 end
+
+ -- sort out selection. same as `do`, but the other way round.
+ for j=i+1,#sel do
+ sel[j] = sel[j] - 1
+ end
+ if act > sel[i] then
+ act = act - 1
+ end
+
end
end
end