Skip to content

Instantly share code, notes, and snippets.

@Willem3141
Created February 17, 2025 18:25
Show Gist options
  • Save Willem3141/a870ba9edd12bd04ed4e4cf7fe080330 to your computer and use it in GitHub Desktop.
Save Willem3141/a870ba9edd12bd04ed4e4cf7fe080330 to your computer and use it in GitHub Desktop.
Ipelet that allows incrementing and decrementing numeric labels (written by Tim Ophelders)
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