Add follow link command to go to or create link
Automatically chooses whether to create a new link or go to an existing file, depending on the existence of a link in the current context (i.e. under the cursor or in selection).
This commit is contained in:
parent
1a58909e94
commit
477ec45d22
3 changed files with 15 additions and 4 deletions
|
|
@ -31,7 +31,10 @@ function A.open_selected(style)
|
|||
ln = t.get_link_under_cursor(links, curpos)
|
||||
end
|
||||
|
||||
if not ln then return false end
|
||||
|
||||
A.open(ln)
|
||||
return true
|
||||
end
|
||||
|
||||
-- Replaces the current text context with a link to a new zettel.
|
||||
|
|
@ -39,7 +42,7 @@ end
|
|||
-- or the (big) word under the cursor if called from any other mode.
|
||||
function A.make_link(visual)
|
||||
local selection, start_col
|
||||
if visual or vim.api.nvim_get_mode()['mode'] == "v" then
|
||||
if visual then
|
||||
selection, start_col = t.get_current_selection()
|
||||
else
|
||||
selection, start_col = t.get_current_word()
|
||||
|
|
|
|||
|
|
@ -22,9 +22,16 @@ function ZK.open_link() return action.open_selected() end
|
|||
-- Create a new link under cursor
|
||||
function ZK.make_link(visual) return action.make_link(visual) end
|
||||
|
||||
-- If invoked in reach of a valid link will try to follow said link.
|
||||
-- Otherwise will take the current context and make a link out of it.
|
||||
function ZK.open_or_make_link(visual)
|
||||
if not ZK.open_link() then ZK.make_link(visual) end
|
||||
end
|
||||
|
||||
return {
|
||||
get_zettel_list = ZK.get_zettel_list,
|
||||
get_anchor = ZK.get_anchor,
|
||||
open_link = ZK.open_link,
|
||||
make_link = ZK.make_link
|
||||
make_link = ZK.make_link,
|
||||
open_or_make_link = ZK.open_or_make_link
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue