feat(forge): add gx keymap to open forge links in browser (#165)

Problem: Forge shorthand tokens like `gh:user/repo#42` are concealed in
the buffer so Neovim's built-in `gx` cannot recognize them as URLs.
Full URLs are also concealed, making `gx` unreliable.

Solution: Add `open_link` action (default `gx`) that reads `forge_spans`
from line metadata. If the cursor is on a forge token, that link opens;
otherwise the last ref on the line is used. Delegates to `vim.ui.open()`.
This commit is contained in:
Barrett Ruth 2026-03-15 11:08:07 -04:00 committed by GitHub
parent f3ef1ca0db
commit 093e699413
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 42 additions and 0 deletions

View file

@ -349,6 +349,7 @@ Default buffer-local keys: ~
`gb` Toggle blocked status (`blocked`)
`g/` Toggle cancelled status (`cancelled`)
`ge` Open markdown detail buffer for task notes (`edit_notes`)
`gx` Open the forge link under the cursor in a browser (`open_link`)
`gf` Prompt for filter predicates (`filter`)
`<Tab>` Switch between category / queue view (`view`)
`gz` Undo the last `:w` save (`undo`)
@ -494,6 +495,13 @@ old keys to `false`: >lua
Shows a read-only metadata header and editable notes below a `---`
separator. Press `q` to return to the task list. Default key: `ge`.
*<Plug>(pending-open-link)*
<Plug>(pending-open-link)
Open the forge link under the cursor in a browser via |vim.ui.open()|.
If the cursor is positioned on a forge token (`gh:user/repo#42` or a
full URL), that link is opened. Otherwise, the last forge reference on
the line is used. No-op on lines without forge links. Default key: `gx`.
*<Plug>(pending-open-line)*
<Plug>(pending-open-line)
Insert a correctly-formatted blank task line below the cursor.

View file

@ -83,6 +83,7 @@
---@field priority_down_visual? string|false
---@field cancelled? string|false
---@field edit_notes? string|false
---@field open_link? string|false
---@class pending.CategoryViewConfig
---@field order? string[]
@ -165,6 +166,7 @@ local defaults = {
blocked = 'gb',
cancelled = 'g/',
edit_notes = 'ge',
open_link = 'gx',
priority_up = '<C-a>',
priority_down = '<C-x>',
priority_up_visual = 'g<C-a>',

View file

@ -404,6 +404,9 @@ function M._setup_buf_mappings(bufnr)
edit_notes = function()
M.open_detail()
end,
open_link = function()
M.open_link()
end,
}
for name, fn in pairs(actions) do
@ -931,6 +934,31 @@ function M.open_detail()
end, { buffer = detail_bufnr })
end
---@return nil
function M.open_link()
local bufnr = buffer.bufnr()
if not bufnr 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 spans = meta[row].forge_spans
if not spans or #spans == 0 then
return
end
local col = vim.api.nvim_win_get_cursor(0)[2]
for _, span in ipairs(spans) do
if col >= span.col_start and col < span.col_end then
vim.ui.open(span.ref.url)
return
end
end
vim.ui.open(spans[#spans].ref.url)
end
---@param direction 'up'|'down'
---@return nil
function M.move_task(direction)

View file

@ -411,6 +411,10 @@ vim.keymap.set('n', '<Plug>(pending-edit-notes)', function()
require('pending').open_detail()
end)
vim.keymap.set('n', '<Plug>(pending-open-link)', function()
require('pending').open_link()
end)
vim.keymap.set('n', '<Plug>(pending-priority-up)', function()
require('pending').increment_priority()
end)