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.
This commit is contained in:
garret 2023-01-15 01:19:53 +00:00
parent 96bd8086c7
commit 5459e401b3
1 changed files with 11 additions and 3 deletions

View File

@ -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