Skip to content

Commit 8e319bf

Browse files
authored
fix(links): insert id link properly (#742)
When inserting a stored id link, it is now properly split into link and description. For this to work with the current implementation we need actually to insert id and headline title both into the link input. It get's split and correctly formatted afterwards. Co-authored-by: Sebastian Flügge <seflue@users.noreply.github.com>
1 parent 1fbc263 commit 8e319bf

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

lua/orgmode/org/hyperlinks/init.lua

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,10 @@ function Hyperlinks.get_link_to_headline(headline, path)
181181
id = headline:id_get_or_create()
182182
end
183183

184-
if not config.org_id_link_to_org_use_id or not id then
185-
return ('file:%s::*%s'):format(path, title)
184+
if config.org_id_link_to_org_use_id and id then
185+
return ('id:%s::*%s'):format(id, title)
186186
end
187-
return ('id:%s %s'):format(id, title)
187+
return ('file:%s::*%s'):format(path, title)
188188
end
189189

190190
---@param headline OrgHeadline
@@ -216,10 +216,9 @@ end
216216
function Hyperlinks.insert_link(link_location)
217217
local selected_link = Link:new(link_location)
218218
local desc = selected_link.url:get_target_value()
219+
219220
if selected_link.url:is_id() then
220-
local id_link = ('id:%s'):format(selected_link.url:get_id())
221-
desc = link_location:gsub('^' .. vim.pesc(id_link) .. '%s+', '')
222-
link_location = id_link
221+
link_location = ('id:%s'):format(selected_link.url:get_id())
223222
end
224223

225224
local link_description = vim.trim(vim.fn.OrgmodeInput('Description: ', desc or ''))

0 commit comments

Comments
 (0)