@@ -50,12 +50,12 @@ function M.refile(closest_headline)
50
50
local entry = action_state .get_selected_entry ()
51
51
actions .close (prompt_bufnr )
52
52
53
- -- Refile to the file by default
54
- local destination = entry .value .file
53
+ local destination = entry .value .headline
54
+ and org .get_api_headline (entry .filename , entry .value .headline .line_number )
55
+ or org .get_api_file (entry .filename )
55
56
56
- -- Refile to a specific heading if is set
57
- if entry .value .headline then
58
- destination = entry .value .headline
57
+ if not destination then
58
+ error (' Could not find destination headline or file' )
59
59
end
60
60
61
61
return org .refile ({
@@ -72,14 +72,15 @@ function M.insert(_)
72
72
--- @type MatchEntry
73
73
local entry = action_state .get_selected_entry ()
74
74
75
- local destination = (function ()
76
- if entry .value .headline then
77
- -- Link to a specific heading if is set
78
- return entry .value .headline :get_link ()
79
- else
80
- return entry .value .file :get_link ()
81
- end
82
- end )()
75
+ local api_object = entry .value .headline
76
+ and org .get_api_headline (entry .filename , entry .value .headline .line_number )
77
+ or org .get_api_file (entry .filename )
78
+
79
+ if not api_object then
80
+ error (' Could not find ' .. (entry .value .headline and ' headline' or ' file' ) .. ' for link' )
81
+ end
82
+
83
+ local destination = api_object :get_link ()
83
84
84
85
org .insert_link (destination )
85
86
return true
0 commit comments