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:
parent
f3ef1ca0db
commit
093e699413
4 changed files with 42 additions and 0 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue