Skip to content

Commit 7fa0c7e

Browse files
committed
feat: support id links to org files
Relies on an api extension of orgmode.
1 parent 3fbb674 commit 7fa0c7e

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

lua/telescope-orgmode/actions.lua

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,14 @@ function M.insert(_)
6060
---@type MatchEntry
6161
local entry = action_state.get_selected_entry()
6262

63-
-- Link to the filename by default
64-
local destination = entry.value.file.filename
65-
66-
-- Link to a specific heading if is set
67-
if entry.value.headline then
68-
destination = org.get_link_to_headline(entry.value.headline)
69-
end
63+
local destination = (function()
64+
if entry.value.headline then
65+
-- Link to a specific heading if is set
66+
return org.get_link_to_headline(entry.value.headline)
67+
else
68+
return org.get_link_to_file(entry.value.file)
69+
end
70+
end)()
7071

7172
org.insert_link(destination)
7273
return true

lua/telescope-orgmode/mappings.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
local config = require('telescope-orgmode.config')
21
local to_actions = require('telescope-orgmode.actions')
32

43
local M = {}

lua/telescope-orgmode/org.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@ end
3131
---@param headline OrgApiHeadline
3232
---@return string
3333
function M.get_link_to_headline(headline)
34-
return OrgApi.get_link_to_headline(headline._section) ---@diagnostic disable-line: invisible
34+
return OrgApi.get_link_to_headline(headline)
35+
end
36+
37+
---@param file OrgApiFile
38+
---@return string
39+
function M.get_link_to_file(file)
40+
return OrgApi.get_link_to_file(file)
3541
end
3642

3743
function M.insert_link(destination)

0 commit comments

Comments
 (0)