diff --git a/macros/garret.dupe-and-comment.lua b/macros/garret.dupe-and-comment.lua index f8e4b4b..f819d40 100644 --- a/macros/garret.dupe-and-comment.lua +++ b/macros/garret.dupe-and-comment.lua @@ -13,11 +13,20 @@ end local function comment(subs, sel, act) for i=#sel,1,-1 do - local line=subs[sel[i]] - line.comment = true - subs.insert(sel[i]+1, line) - for j=i+1,#sel do sel[j] = sel[j] + 1 end - if act > sel[i] then act = act + 1 end + local line=subs[sel[i]] -- grab copy of current line + + -- now use that copy for a different line + line.comment = true -- comment out the new dupe line + subs.insert(sel[i]+1, line) -- and put it below + + -- sort out selection + for j=i+1,#sel do + sel[j] = sel[j] + 1 -- bump all of sel by 1 to compensate for new line + end -- first item isnt included because it's not affected + + if act > sel[i] then -- if we've not got to the active line yet + act = act + 1 -- bump by 1 to compensate for new lines above + end end aegisub.set_undo_point(script_name) return sel, act