diff options
author | garret <garret@airmail.cc> | 2023-01-17 22:50:58 +0000 |
---|---|---|
committer | garret <garret@airmail.cc> | 2023-01-17 22:50:58 +0000 |
commit | 2a6b5d36854b0e811529f0954453ea72052e4e15 (patch) | |
tree | cb389d0d650830198bcf31aa2cd2e6fc30135341 /macros/garret.dupe-and-comment.lua | |
parent | 016ef8486d8320818879aebc3b8a6228ca28b4c5 (diff) | |
download | aegisub-scripts-2a6b5d36854b0e811529f0954453ea72052e4e15.tar.gz aegisub-scripts-2a6b5d36854b0e811529f0954453ea72052e4e15.tar.bz2 aegisub-scripts-2a6b5d36854b0e811529f0954453ea72052e4e15.zip |
dupe&comment: new way of fixing sel/act that i understand even less
though apparently it's a bit faster
Co-Authored-By: Akatsumekusa <Akatsumekusa@protonmail.com>
Diffstat (limited to 'macros/garret.dupe-and-comment.lua')
-rw-r--r-- | macros/garret.dupe-and-comment.lua | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/macros/garret.dupe-and-comment.lua b/macros/garret.dupe-and-comment.lua index 14a660c..4b3c2d6 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 = "3.0.0" +script_version = "3.0.1" script_namespace = "garret.dupe-and-comment" local haveDepCtrl, DependencyControl, depctrl = pcall(require, "l0.DependencyControl") @@ -19,14 +19,13 @@ 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 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 + -- 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 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 @@ -44,12 +43,11 @@ local function undo(subs, sel, act) subs.delete(sel[i]) -- sort out selection. same as `do`, but the other way round. - for j=i+1,#sel do - sel[j] = sel[j] - 1 - end - if act > sel[i] then - act = act - 1 - end + local preceding_lines = i + 1 + local on_act = act == sel[i] + + sel[i] = sel[i] - following_lines + if on_act then act = sel[i] end end end |