Created
February 17, 2025 18:25
-
-
Save Willem3141/a870ba9edd12bd04ed4e4cf7fe080330 to your computer and use it in GitHub Desktop.
Ipelet that allows incrementing and decrementing numeric labels (written by Tim Ophelders)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
label = "Increment" | |
about = [[ | |
Increment the first numerical value in selected text objects. | |
]] | |
function foo(model,num) | |
local f | |
if num == 1 then | |
f = function (v) return v+1 end | |
elseif num == 2 then | |
f = function (v) return v-1 end | |
end | |
local t = { label = label, | |
pno = model.pno, | |
vno = model.vno, | |
original = model:page():clone(), | |
final = model:page():clone(), | |
undo = _G.revertOriginal, | |
redo = _G.revertFinal, | |
} | |
for i,obj,sel,layer in t.final:objects() do | |
if sel and obj:type() == "text" then | |
local text = obj:text() | |
local a = string.match(text,"-?%d+") | |
if a ~= nil then | |
obj:setText(string.gsub(text,a,string.format('%d',f(tonumber(a))),1)) | |
end | |
end | |
end | |
model:register(t) | |
end | |
---------------------------------------------------------------------- | |
methods = { | |
{ label = "Increment", run=foo }, | |
{ label = "Decrement", run=foo }, | |
} | |
shortcuts.ipelet_1_increment = "Alt+PgUp" | |
shortcuts.ipelet_2_increment = "Alt+PgDown" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment