From 3159a91f20d44f739c7f20f6602f10fb2e6cd8e1 Mon Sep 17 00:00:00 2001 From: garret Date: Sun, 29 Jan 2023 23:45:41 +0000 Subject: dupe and comment: don't do sel/act stuff if only one line --- macros/garret.dupe-and-comment.lua | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/macros/garret.dupe-and-comment.lua b/macros/garret.dupe-and-comment.lua index 4b3c2d6..198a905 100644 --- a/macros/garret.dupe-and-comment.lua +++ b/macros/garret.dupe-and-comment.lua @@ -19,13 +19,14 @@ local function comment(subs, sel, act) line.comment = true -- comment out the new dupe line subs.insert(sel[i]+1, line) -- and put it below - -- sort out sel/act - local preceding_lines = i - 1 - local on_act = act == sel[i] - - sel[i] = sel[i] + preceding_lines - if on_act then act = sel[i] end +-- if #sel > 1 then + -- sort out sel/act + local preceding_lines = i - 1 + local on_act = act == sel[i] + sel[i] = sel[i] + preceding_lines + if on_act then act = sel[i] end +-- end end aegisub.set_undo_point(script_name) return sel, act @@ -42,12 +43,14 @@ local function undo(subs, sel, act) subs[sel[i]+1] = original subs.delete(sel[i]) + if #sel > 1 then -- sort out selection. same as `do`, but the other way round. local preceding_lines = i + 1 local on_act = act == sel[i] - sel[i] = sel[i] - following_lines + sel[i] = sel[i] - preceding_lines if on_act then act = sel[i] end + end end end -- cgit v1.2.3-70-g09d2