feat: add <C-a> / <C-x> keymaps for priority increment/decrement

Problem: Priority could only be cycled with `g!` (0→1→2→3→0), with no
way to directly increment or decrement.

Solution: Add `adjust_priority()` with clamping at 0 and `max_priority`,
exposed as `increment_priority()` / `decrement_priority()` on `<C-a>` /
`<C-x>`. Includes `<Plug>` mappings and vimdoc.
This commit is contained in:
Barrett Ruth 2026-03-08 20:30:51 -04:00
parent cfcaaca28b
commit ec1d4c6092
4 changed files with 78 additions and 0 deletions

View file

@ -137,6 +137,8 @@ local defaults = {
move_up = 'K',
wip = 'gw',
blocked = 'gb',
priority_up = '<C-a>',
priority_down = '<C-x>',
},
sync = {},
icons = {

View file

@ -363,6 +363,12 @@ function M._setup_buf_mappings(bufnr)
blocked = function()
M.toggle_status('blocked')
end,
priority_up = function()
M.increment_priority()
end,
priority_down = function()
M.decrement_priority()
end,
undo = function()
M.undo_write()
end,
@ -646,6 +652,56 @@ function M.toggle_priority()
end
end
---@param delta integer
---@return nil
local function adjust_priority(delta)
local bufnr = buffer.bufnr()
if not bufnr then
return
end
if not require_saved() then
return
end
local row = vim.api.nvim_win_get_cursor(0)[1]
local meta = buffer.meta()
if not meta[row] or meta[row].type ~= 'task' then
return
end
local id = meta[row].id
if not id then
return
end
local s = get_store()
local task = s:get(id)
if not task then
return
end
local max = require('pending.config').get().max_priority or 3
local new_priority = math.max(0, math.min(max, task.priority + delta))
if new_priority == task.priority then
return
end
s:update(id, { priority = new_priority })
_save_and_notify()
buffer.render(bufnr)
for lnum, m in ipairs(buffer.meta()) do
if m.id == id then
vim.api.nvim_win_set_cursor(0, { lnum, 0 })
break
end
end
end
---@return nil
function M.increment_priority()
adjust_priority(1)
end
---@return nil
function M.decrement_priority()
adjust_priority(-1)
end
---@return nil
function M.prompt_date()
local bufnr = buffer.bufnr()