From 5d3c4f0e6c60aec90540de4a32594122ab9e799e Mon Sep 17 00:00:00 2001 From: garret Date: Sat, 24 Dec 2022 16:00:13 +0000 Subject: dupe and comment: fix out of range error in undo --- macros/garret.dupe-and-comment.lua | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'macros/garret.dupe-and-comment.lua') diff --git a/macros/garret.dupe-and-comment.lua b/macros/garret.dupe-and-comment.lua index c445bfb..a434712 100644 --- a/macros/garret.dupe-and-comment.lua +++ b/macros/garret.dupe-and-comment.lua @@ -1,7 +1,7 @@ script_name="Dupe and Comment" script_description="Copies a line and comments out the original.\nbecause i like seeing the original while editing, and being able to go back to it easily" script_author = "garret" -script_version = "2.1.2" +script_version = "2.1.3" script_namespace = "garret.dupe-and-comment" local haveDepCtrl, DependencyControl, depctrl = pcall(require, "l0.DependencyControl") @@ -30,11 +30,13 @@ end local function undo(subs, sel) for i=#sel,1,-1 do local edit=subs[sel[i]] - 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]) + if not (sel[i] + 1 > #subs) then + 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]) + end end end aegisub.set_undo_point("Undo "..script_name) -- cgit v1.2.3-70-g09d2