File tree 2 files changed +19
-7
lines changed
2 files changed +19
-7
lines changed Original file line number Diff line number Diff line change 1
1
local utils = require (' orgmode.utils' )
2
+ local fs = require (' orgmode.utils.fs' )
2
3
local OrgLinkUrl = require (' orgmode.org.links.url' )
3
4
local link_utils = require (' orgmode.org.links.utils' )
4
5
@@ -74,6 +75,19 @@ function OrgLinkHeadlineSearch:autocomplete(link)
74
75
f = f :gsub (' ^' .. opts .file_path , opts .link_url .path )
75
76
table.insert (valid_filenames , f )
76
77
end
78
+
79
+ local real_path = opts .link_url :get_real_path ()
80
+
81
+ if not real_path then
82
+ local substitute_path = fs .substitute_path (opts .file_path )
83
+ if substitute_path then
84
+ local full_path = vim .fn .fnamemodify (substitute_path , ' :p' )
85
+ if f :find (' ^' .. full_path ) then
86
+ f = f :gsub (' ^' .. full_path , opts .link_url .path )
87
+ table.insert (valid_filenames , f )
88
+ end
89
+ end
90
+ end
77
91
end
78
92
79
93
local prefix = opts .link_url :get_protocol () == ' file' and ' file:' or ' '
Original file line number Diff line number Diff line change 20
20
--- @return string | nil
21
21
function OrgLinkUrl :get_file_path ()
22
22
if self .protocol == ' file' then
23
- return self :_get_real_path ()
23
+ return self :get_real_path () or self . path
24
24
end
25
25
26
26
local first_char = self .path :sub (1 , 1 )
27
27
28
28
if first_char == ' /' then
29
- return self :_get_real_path ()
29
+ return self :get_real_path () or self . path
30
30
end
31
31
32
32
if
33
33
(first_char == ' .' and (self .path :sub (1 , 3 ) == ' ../' or self .path :sub (1 , 2 ) == ' ./' ))
34
34
or (first_char == ' ~' and self .path :sub (2 , 2 ) == ' /' )
35
35
then
36
- return self :_get_real_path ()
36
+ return self :get_real_path () or self . path
37
37
end
38
38
39
39
return nil
@@ -76,10 +76,8 @@ function OrgLinkUrl:get_id()
76
76
return self .path
77
77
end
78
78
79
- --- @private
80
- --- @return string
81
- function OrgLinkUrl :_get_real_path ()
82
- return fs .get_real_path (self .path ) or self .path
79
+ function OrgLinkUrl :get_real_path ()
80
+ return fs .get_real_path (self .path ) or nil
83
81
end
84
82
85
83
--- @return string
You can’t perform that action at this time.
0 commit comments