From c7ada7881d7076a235b6323edcd81ae260affb41 Mon Sep 17 00:00:00 2001 From: Devansh Sharma <21225957+devansh08@users.noreply.github.com> Date: Sun, 17 Nov 2024 01:48:12 +0530 Subject: [PATCH] feat(esupports.hop): Add tab drop as option for open_mode (#1580) * feat(esupports.hop): Add tab drop as option for open_mode * docs(esupports.hop): Document keybinds for tab-drop * feat(esupports.hop): Add drop as option for open_mode --- .../modules/core/esupports/hop/module.lua | 20 ++++++++++++++++--- lua/neorg/modules/core/keybinds/module.lua | 8 ++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/lua/neorg/modules/core/esupports/hop/module.lua b/lua/neorg/modules/core/esupports/hop/module.lua index eddfedff8..fadcb20b3 100644 --- a/lua/neorg/modules/core/esupports/hop/module.lua +++ b/lua/neorg/modules/core/esupports/hop/module.lua @@ -17,6 +17,10 @@ mapping them): - `neorg.esupports.hop.hop-link` - Follow the link under the cursor, seeks forward - `neorg.esupports.hop.hop-link.vsplit` - Same, but open the link in a vertical split +- `neorg.esupports.hop.hop-link.tab-drop` - Same as hop-link, but open the link in a new tab; if the destination is already + open in an existing tab then just navigate to that tab (check :help :drop) +- `neorg.esupports.hop.hop-link.drop` - Same as hop-link, but navigate to the buffer if the destination is already open + in an existing buffer (check :help :drop) --]] local neorg = require("neorg.core") @@ -42,6 +46,8 @@ module.load = function() dirman_utils = module.required["core.dirman.utils"] vim.keymap.set("", "(neorg.esupports.hop.hop-link)", module.public.hop_link) vim.keymap.set("", "(neorg.esupports.hop.hop-link.vsplit)", lib.wrap(module.public.hop_link, "vsplit")) + vim.keymap.set("", "(neorg.esupports.hop.hop-link.drop)", lib.wrap(module.public.hop_link, "drop")) + vim.keymap.set("", "(neorg.esupports.hop.hop-link.tab-drop)", lib.wrap(module.public.hop_link, "tab-drop")) end module.config.public = { @@ -216,11 +222,19 @@ module.public = { end, buffer = function() - open_split() + if open_mode ~= "tab-drop" and open_mode ~= "drop" then + open_split() + end if located_link_information.buffer ~= vim.api.nvim_get_current_buf() then - vim.api.nvim_buf_set_option(located_link_information.buffer, "buflisted", true) - vim.api.nvim_set_current_buf(located_link_information.buffer) + if open_mode == "tab-drop" then + vim.cmd("tab drop " .. vim.api.nvim_buf_get_name(located_link_information.buffer)) + elseif open_mode == "drop" then + vim.cmd("drop " .. vim.api.nvim_buf_get_name(located_link_information.buffer)) + else + vim.api.nvim_buf_set_option(located_link_information.buffer, "buflisted", true) + vim.api.nvim_set_current_buf(located_link_information.buffer) + end end if located_link_information.line then diff --git a/lua/neorg/modules/core/keybinds/module.lua b/lua/neorg/modules/core/keybinds/module.lua index d66d8ffb8..63ec941d3 100644 --- a/lua/neorg/modules/core/keybinds/module.lua +++ b/lua/neorg/modules/core/keybinds/module.lua @@ -298,6 +298,14 @@ module.private = { opts = { desc = "[neorg] Jump to Link (Vertical Split)" }, }, + -- Same as ``, except open the destination in a new tab + -- If destination is already open in an existing tab, just navigate to it + { + "", + "(neorg.esupports.hop.hop-link.tab-drop)", + opts = { desc = "[neorg] Jump to Link (Tab Drop)" }, + }, + -- Promote an object non-recursively { ">.",