Skip to content

Commit

Permalink
refactor!: move esupports.hop to the new keybind schema
Browse files Browse the repository at this point in the history
  • Loading branch information
vhyrro committed Jul 13, 2024
1 parent ecf5f41 commit cdfbe19
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 24 deletions.
35 changes: 15 additions & 20 deletions lua/neorg/modules/core/esupports/hop/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ end
module.load = function()
links = module.required["core.links"]
dirman_utils = module.required["core.dirman.utils"]
modules.await("core.keybinds", function(keybinds)
keybinds.register_keybind(module.name, "hop-link")
end)
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"))
end

module.config.public = {
Expand Down Expand Up @@ -677,6 +676,19 @@ module.public = {
end,
} --[[@as table<string, fun(): LinkTarget?>]])
end,

hop_link = function(split_mode)
local link_node_at_cursor = module.public.extract_link_node()

if not link_node_at_cursor then
log.trace("No link under cursor.")
return
end

local parsed_link = module.public.parse_link(link_node_at_cursor)

module.public.follow_link(link_node_at_cursor, split_mode, parsed_link)
end
}

module.private = {
Expand Down Expand Up @@ -946,23 +958,6 @@ module.private = {
end,
}

module.on_event = function(event)
if event.split_type[2] == "core.esupports.hop.hop-link" then
local split_mode = event.content[1]

local link_node_at_cursor = module.public.extract_link_node()

if not link_node_at_cursor then
log.trace("No link under cursor.")
return
end

local parsed_link = module.public.parse_link(link_node_at_cursor)

module.public.follow_link(link_node_at_cursor, split_mode, parsed_link)
end
end

module.events.subscribed = {
["core.keybinds"] = {
["core.esupports.hop.hop-link"] = true,
Expand Down
7 changes: 4 additions & 3 deletions lua/neorg/modules/core/keybinds/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,10 @@ module.private = {

-- Hop to the destination of the link under the cursor
{ "<CR>", "<Plug>(neorg.esupports.hop.hop-link)", opts = { desc = "[neorg] Jump to Link" } },
{ "gd", "<Plug>(neorg.esupports.hop.hop-link)", opts = { desc = "[neorg] Jump to Link" } },
{ "gf", "<Plug>(neorg.esupports.hop.hop-link)", opts = { desc = "[neorg] Jump to Link" } },
{ "gF", "<Plug>(neorg.esupports.hop.hop-link)", opts = { desc = "[neorg] Jump to Link" } },
-- TODO: Move these to the "vim" preset
-- { "gd", "<Plug>(neorg.esupports.hop.hop-link)", opts = { desc = "[neorg] Jump to Link" } },
-- { "gf", "<Plug>(neorg.esupports.hop.hop-link)", opts = { desc = "[neorg] Jump to Link" } },
-- { "gF", "<Plug>(neorg.esupports.hop.hop-link)", opts = { desc = "[neorg] Jump to Link" } },

-- Same as `<CR>`, except opens the destination in a vertical split
{
Expand Down
1 change: 0 additions & 1 deletion lua/neorg/modules/core/qol/todo_items/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,6 @@ module.private = {
end

module.public = {

task_done = task_set("x", "done"),
task_undone = task_set(" ", "undone"),
task_pending = task_set("-", "pending"),
Expand Down

0 comments on commit cdfbe19

Please sign in to comment.