aboutsummaryrefslogtreecommitdiffstats
path: root/macros/garret.dupe-and-comment.lua
diff options
context:
space:
mode:
authorgarret <garret@airmail.cc>2023-01-29 23:45:41 +0000
committergarret <garret@airmail.cc>2023-01-29 23:46:49 +0000
commit3159a91f20d44f739c7f20f6602f10fb2e6cd8e1 (patch)
tree6c0576b9eab46fbea77fbb412bfb93a94d2ccf94 /macros/garret.dupe-and-comment.lua
parent78033c041f83f1868a98551931a53735f5154cbc (diff)
downloadaegisub-scripts-3159a91f20d44f739c7f20f6602f10fb2e6cd8e1.tar.gz
aegisub-scripts-3159a91f20d44f739c7f20f6602f10fb2e6cd8e1.tar.bz2
aegisub-scripts-3159a91f20d44f739c7f20f6602f10fb2e6cd8e1.zip
dupe and comment: don't do sel/act stuff if only one line
Diffstat (limited to 'macros/garret.dupe-and-comment.lua')
-rw-r--r--macros/garret.dupe-and-comment.lua17
1 files 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