feat(CountersSelector): add 'm' shortcut

This commit is contained in:
Guillaume ARM 2024-05-23 22:19:38 +02:00
parent 56558fad7a
commit 69b31f24a9

View File

@ -131,7 +131,7 @@ local function renderTitle(win, countersMap, selectedCounter, titleFn)
end)
end
local function incrementCounter(countersMap, selectedCounter)
local function incrementSelectedCounter(countersMap, selectedCounter)
local counterPayload = countersMap[selectedCounter]
if counterPayload and counterPayload.count then
@ -146,7 +146,7 @@ local function incrementCounter(countersMap, selectedCounter)
return false
end
local function decrementCounter(countersMap, selectedCounter)
local function decrementSelectedCounter(countersMap, selectedCounter)
local counterPayload = countersMap[selectedCounter]
if counterPayload and counterPayload.count and counterPayload.count > 0 then
@ -161,6 +161,24 @@ local function decrementCounter(countersMap, selectedCounter)
return false
end
local function switchMinMaxSelectedCounter(countersMap, selectedCounter, maxPossibleCount)
local counterPayload = countersMap[selectedCounter]
if counterPayload and counterPayload.count then
if counterPayload.count > 0 then
countersMap[selectedCounter] = {
count = 0,
name = counterPayload.name
}
else
countersMap[selectedCounter] = {
count = maxPossibleCount,
name = counterPayload.name
}
end
end
end
local function CountersSelector(initialCountersMap, config)
local countersMap = utils.shallowClone(initialCountersMap)
local counterMax = config.counterMax
@ -201,15 +219,19 @@ local function CountersSelector(initialCountersMap, config)
elseif keyPressed == keys.down then
selectedCounter = math.min(nbCounters, selectedCounter + 1)
elseif keyPressed == keys.left and globalCounter > 0 then
if decrementCounter(countersMap, selectedCounter) then
if decrementSelectedCounter(countersMap, selectedCounter) then
globalCounter = globalCounter - 1
end
elseif keyPressed == keys.right and globalCounter < counterMax then
if incrementCounter(countersMap, selectedCounter) then
if incrementSelectedCounter(countersMap, selectedCounter) then
globalCounter = globalCounter + 1
end
elseif keyPressed == keys.m then
switchMinMaxSelectedCounter(countersMap, selectedCounter, counterMax - globalCounter)
globalCounter = getTotalCount(countersMap)
elseif keyPressed == keys.r then
countersMap = resetAllCounters(countersMap)
globalCounter = 0
elseif keyPressed == keys.enter then
shouldContinue = false
elseif keypRessed == keys.q then