Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(esupports.hop): Add tab drop as option for open_mode #1580

Merged
merged 6 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions lua/neorg/modules/core/esupports/hop/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -42,6 +46,8 @@ module.load = function()
dirman_utils = module.required["core.dirman.utils"]
vim.keymap.set("", "<Plug>(neorg.esupports.hop.hop-link)", module.public.hop_link)
vim.keymap.set("", "<Plug>(neorg.esupports.hop.hop-link.vsplit)", lib.wrap(module.public.hop_link, "vsplit"))
vim.keymap.set("", "<Plug>(neorg.esupports.hop.hop-link.drop)", lib.wrap(module.public.hop_link, "drop"))
vim.keymap.set("", "<Plug>(neorg.esupports.hop.hop-link.tab-drop)", lib.wrap(module.public.hop_link, "tab-drop"))
end

module.config.public = {
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions lua/neorg/modules/core/keybinds/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,14 @@ module.private = {
opts = { desc = "[neorg] Jump to Link (Vertical Split)" },
},

-- Same as `<CR>`, except open the destination in a new tab
-- If destination is already open in an existing tab, just navigate to it
{
benlubas marked this conversation as resolved.
Show resolved Hide resolved
"<M-t>",
"<Plug>(neorg.esupports.hop.hop-link.tab-drop)",
opts = { desc = "[neorg] Jump to Link (Tab Drop)" },
},

-- Promote an object non-recursively
{
">.",
Expand Down
Loading