-
-
Notifications
You must be signed in to change notification settings - Fork 168
fix(links): insert id link properly #742
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
return ('id:%s::*%s'):format(id, title) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -216,10 +216,9 @@ end | |
function Hyperlinks.insert_link(link_location) | ||
local selected_link = Link:new(link_location) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 '')) | ||
|
There was a problem hiding this comment.
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).