diff --git a/README.md b/README.md index 45e2953..5f79872 100644 --- a/README.md +++ b/README.md @@ -227,6 +227,10 @@ Available subcommands, > Subcommands that end with `{n}` can also take a buffer id. If a buffer id isn't provided then the current buffer's id is used. > Completion for buffer id is also provided by the plugin. +Additional command(s), + +- `MarkOpen`, Opens the link under cursor, falls back to **vim.ui.open()**. + ## 🎨 Highlight groups
diff --git a/lua/markview/keymaps.lua b/lua/markview/keymaps.lua
index cfc4d6d..5c3764d 100644
--- a/lua/markview/keymaps.lua
+++ b/lua/markview/keymaps.lua
@@ -4,51 +4,54 @@ local keymaps = {};
keymaps.views = {};
keymaps.on_bufs = {};
-keymaps.createKeymap = function (buffer)
- vim.api.nvim_buf_set_keymap(buffer, "n", "gx", "", {
- desc = "gx implamentation for Markview.nvim",
- callback = function ()
- local buf_links = keymaps.views[buffer] or {};
- local cursor = vim.api.nvim_win_get_cursor(0);
-
- --- Iterate over all the available links
- for _, link in ipairs(buf_links) do
- --- Cursor isn't on the line of the link
- if link.row_start + 1 ~= cursor[1] then
- goto continue;
- end
-
- --- Cursor isn't on the column range of the link
- if cursor[2] < link.col_start or cursor[2] > link.col_end then
- goto continue;
- end
-
- --- Modify the address and open it in `vim.ui.open()`
- local cmd, err = vim.ui.open(vim.fn.fnamemodify(link.address, ":~"))
-
- if err then
- vim.notify("[ Markview.nvim ] : Failed to open: " .. link.address, vim.diagnostic.severity.WARN)
- break;
- end
-
- if cmd then
- cmd:wait();
- break;
- end
-
- ::continue::
+keymaps.create_command = function (buffer)
+ vim.api.nvim_buf_create_user_command(buffer, "MarkOpen", function ()
+ local buf_links = keymaps.views[buffer] or {};
+ local cursor = vim.api.nvim_win_get_cursor(0);
+
+ --- Iterate over all the available links
+ for _, link in ipairs(buf_links) do
+ --- Cursor isn't on the line of the link
+ if link.row_start + 1 ~= cursor[1] then
+ goto continue;
+ end
+
+ --- Cursor isn't on the column range of the link
+ if cursor[2] < link.col_start or cursor[2] > link.col_end then
+ goto continue;
end
- local def_cmd, def_err = vim.ui.open(vim.fn.expand("