@@ -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,6 +66,10 @@ 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 )
69
74
end , 0 )
70
75
vim .cmd ([[ autocmd! OrgCapture BufWipeout <buffer>]] )
@@ -133,13 +138,19 @@ function Capture:_refile_content_with_fallback(lines, fallback_file, item)
133
138
end
134
139
135
140
local destination_file = valid_destinations [destination [1 ]]
136
-
137
141
if not destination [2 ] or destination [2 ] == ' ' then
138
142
return self :_refile_to_end (destination_file , lines , item )
139
143
end
144
+ return self :refile_to_headline (destination_file , lines , item , destination [2 ])
145
+ end
140
146
147
+ function Capture :refile_to_headline (destination_file , lines , item , headline_title )
141
148
local agenda_file = Files .get (destination_file )
142
- local headline = agenda_file :find_headline_by_title (destination [2 ])
149
+ local headline
150
+ if headline_title then
151
+ headline = agenda_file :find_headline_by_title (headline_title )
152
+ end
153
+
143
154
if not headline then
144
155
return self ._refile_to_end (destination_file , lines , item )
145
156
end
0 commit comments