aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/ui.lua
diff options
context:
space:
mode:
authordundargoc <gocdundar@gmail.com>2024-05-03 20:32:06 +0200
committerdundargoc <33953936+dundargoc@users.noreply.github.com>2024-05-24 11:07:43 +0200
commitf864b68c5b0fe1482249167712cd16ff2b50ec45 (patch)
treee8361e05037eceaeba92c021a19451704e3ba6df /runtime/lua/vim/ui.lua
parent6dc62c2e2b413a9bbaf0746660c5638936303249 (diff)
downloadrneovim-f864b68c5b0fe1482249167712cd16ff2b50ec45.tar.gz
rneovim-f864b68c5b0fe1482249167712cd16ff2b50ec45.tar.bz2
rneovim-f864b68c5b0fe1482249167712cd16ff2b50ec45.zip
feat: allow gx to function for markdown links
In other words, `gx` works regardless of where it was used in `[...](https://...)`. This only works on markdown buffers. Co-authored-by: ribru17 <ribru17@gmail.com>
Diffstat (limited to 'runtime/lua/vim/ui.lua')
-rw-r--r--runtime/lua/vim/ui.lua20
1 files changed, 20 insertions, 0 deletions
diff --git a/runtime/lua/vim/ui.lua b/runtime/lua/vim/ui.lua
index 3c947c51b0..99b9b78e2a 100644
--- a/runtime/lua/vim/ui.lua
+++ b/runtime/lua/vim/ui.lua
@@ -162,4 +162,24 @@ function M.open(path)
return vim.system(cmd, { text = true, detach = true }), nil
end
+--- Gets the URL at cursor, if any.
+function M._get_url()
+ if vim.bo.filetype == 'markdown' then
+ local range = vim.api.nvim_win_get_cursor(0)
+ vim.treesitter.get_parser():parse(range)
+ -- marking the node as `markdown_inline` is required. Setting it to `markdown` does not
+ -- work.
+ local current_node = vim.treesitter.get_node { lang = 'markdown_inline' }
+ while current_node do
+ local type = current_node:type()
+ if type == 'inline_link' or type == 'image' then
+ local child = assert(current_node:named_child(1))
+ return vim.treesitter.get_node_text(child, 0)
+ end
+ current_node = current_node:parent()
+ end
+ end
+ return vim.fn.expand('<cfile>')
+end
+
return M