diff options
author | Akatsumekusa <Akatsumekusa@protonmail.com> | 2023-01-13 11:56:34 +0000 |
---|---|---|
committer | garret <garret@airmail.cc> | 2023-01-15 13:26:09 +0000 |
commit | b2f27bd080dd52f1a4e93019701ad4254f5d6176 (patch) | |
tree | dcd4bb52592325988b613390b5f26c6391982d42 /macros | |
parent | 12fe89b0b930500e694f5b977f6b4a48f4af8137 (diff) | |
download | aegisub-scripts-b2f27bd080dd52f1a4e93019701ad4254f5d6176.tar.gz aegisub-scripts-b2f27bd080dd52f1a4e93019701ad4254f5d6176.tar.bz2 aegisub-scripts-b2f27bd080dd52f1a4e93019701ad4254f5d6176.zip |
dupe and comment: fix sel and act
selected lines and active line will
now be properly set after do and undo
removed aegisub.util from requiredModules
Diffstat (limited to 'macros')
-rw-r--r-- | macros/garret.dupe-and-comment.lua | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/macros/garret.dupe-and-comment.lua b/macros/garret.dupe-and-comment.lua index a434712..f8e4b4b 100644 --- a/macros/garret.dupe-and-comment.lua +++ b/macros/garret.dupe-and-comment.lua @@ -5,29 +5,25 @@ script_version = "2.1.3" script_namespace = "garret.dupe-and-comment" local haveDepCtrl, DependencyControl, depctrl = pcall(require, "l0.DependencyControl") -local util if haveDepCtrl then depctrl = DependencyControl { --feed="TODO", - {"aegisub.util"} } - util = depctrl:requireModules() -else - util = require 'aegisub.util' end -local function comment(subs, sel) +local function comment(subs, sel, act) for i=#sel,1,-1 do local line=subs[sel[i]] - local original = util.copy(line) - line.comment = false -- going to edit it, so we probably want to see it on the video - original.comment = true -- this is the actual original one - subs.insert(sel[i]+1, original) -- putting it on the next line so i don't have to change line + 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 end aegisub.set_undo_point(script_name) + return sel, act end -local function undo(subs, sel) +local function undo(subs, sel, act) for i=#sel,1,-1 do local edit=subs[sel[i]] if not (sel[i] + 1 > #subs) then @@ -36,10 +32,13 @@ local function undo(subs, sel) 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 end end end aegisub.set_undo_point("Undo "..script_name) + return sel, act end local macros = { |