Skip to content
Merged
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
11 changes: 5 additions & 6 deletions lua/orgmode/org/hyperlinks/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,10 @@ function Hyperlinks.get_link_to_headline(headline, path)
id = headline:id_get_or_create()
end

if not config.org_id_link_to_org_use_id or not id then
return ('file:%s::*%s'):format(path, title)
if config.org_id_link_to_org_use_id and id then
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just swapped the logic for easier readability (no double negation).

return ('id:%s::*%s'):format(id, title)
Copy link
Contributor Author

@seflue seflue Jun 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the same url syntax as in file links enables the Url class to parse the parts correctly the existing parsing logic.

end
return ('id:%s %s'):format(id, title)
return ('file:%s::*%s'):format(path, title)
end

---@param headline OrgHeadline
Expand Down Expand Up @@ -216,10 +216,9 @@ end
function Hyperlinks.insert_link(link_location)
local selected_link = Link:new(link_location)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The full url including the description a.k.a. headline title is inserted by the user via autocompletion. Link construction parses it and we can get the parts needed parts easily from it to assemble the actual link.

local desc = selected_link.url:get_target_value()

if selected_link.url:is_id() then
local id_link = ('id:%s'):format(selected_link.url:get_id())
desc = link_location:gsub('^' .. vim.pesc(id_link) .. '%s+', '')
link_location = id_link
link_location = ('id:%s'):format(selected_link.url:get_id())
end

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