@@ -20,6 +20,41 @@ function OrgHyperlink:new(str, range)
20
20
return this
21
21
end
22
22
23
+ --- Get hyperlink under current cursor position by parsing the line
24
+ --- @return OrgHyperlink | nil
25
+ function OrgHyperlink .from_current_line_position ()
26
+ local pos = vim .fn .getpos (' .' )
27
+ local line = vim .api .nvim_get_current_line ()
28
+ local start_pos = 0
29
+ local end_pos = 0
30
+ for i = pos [3 ], 1 , - 1 do
31
+ if line :sub (i , i ) == ' [' and line :sub (i - 1 , i - 1 ) == ' [' then
32
+ start_pos = i - 1
33
+ break
34
+ end
35
+ end
36
+ for i = pos [3 ], # line do
37
+ if line :sub (i , i ) == ' ]' and line :sub (i + 1 , i + 1 ) == ' ]' then
38
+ end_pos = i + 1
39
+ break
40
+ end
41
+ end
42
+
43
+ if start_pos == 0 or end_pos == 0 then
44
+ return nil
45
+ end
46
+ local str = line :sub (start_pos + 2 , end_pos - 2 )
47
+ return OrgHyperlink :new (
48
+ str ,
49
+ Range :new ({
50
+ start_line = pos [2 ],
51
+ start_col = start_pos ,
52
+ end_line = pos [2 ],
53
+ end_col = end_pos ,
54
+ })
55
+ )
56
+ end
57
+
23
58
--- @param node TSNode
24
59
--- @param source number | string
25
60
--- @return OrgHyperlink
@@ -33,6 +68,7 @@ function OrgHyperlink.from_node(node, source)
33
68
return this
34
69
end
35
70
71
+ --- Get hyperlink under current cursor position by parsing the treesitter node
36
72
--- @return OrgHyperlink | nil
37
73
function OrgHyperlink .at_cursor ()
38
74
local link_node = ts_utils .closest_node (ts_utils .get_node (), { ' link' , ' link_desc' })
0 commit comments