@@ -56,6 +56,7 @@ function Capture:refile(confirm)
56
56
local template = vim .api .nvim_buf_get_var (0 , ' org_template' ) or {}
57
57
local file = vim .fn .fnamemodify (template .target or config .org_default_notes_file , ' :p' )
58
58
local lines = vim .api .nvim_buf_get_lines (0 , 0 , - 1 , true )
59
+ local headline_title = template .headline
59
60
if confirm and is_modified then
60
61
local choice = vim .fn .confirm (string.format (' Do you want to refile this to %s?' , file ), ' &Yes\n &No' )
61
62
vim .cmd ([[ redraw!]] )
@@ -65,7 +66,12 @@ function Capture:refile(confirm)
65
66
end
66
67
vim .defer_fn (function ()
67
68
-- TODO: Parse refile content as org file and update refile destination to point to headline or root
69
+ if headline_title then
70
+ self :refile_to_headline (file , lines , nil , headline_title )
71
+ return
72
+ end
68
73
self :_refile_to_end (file , lines )
74
+
69
75
end , 0 )
70
76
vim .cmd ([[ autocmd! OrgCapture BufWipeout <buffer>]] )
71
77
vim .cmd ([[ silent! wq]] )
@@ -133,13 +139,19 @@ function Capture:_refile_content_with_fallback(lines, fallback_file, item)
133
139
end
134
140
135
141
local destination_file = valid_destinations [destination [1 ]]
136
-
137
142
if not destination [2 ] or destination [2 ] == ' ' then
138
143
return self :_refile_to_end (destination_file , lines , item )
139
144
end
145
+ return self :refile_to_headline (destination_file , lines , item , destination [2 ]);
146
+ end
140
147
148
+ function Capture :refile_to_headline (destination_file , lines , item , headline_title )
141
149
local agenda_file = Files .get (destination_file )
142
- local headline = agenda_file :find_headline_by_title (destination [2 ])
150
+ local headline
151
+ if headline_title then
152
+ headline = agenda_file :find_headline_by_title (headline_title )
153
+ end
154
+
143
155
if not headline then
144
156
return self ._refile_to_end (destination_file , lines , item )
145
157
end
0 commit comments