@@ -8,50 +8,29 @@ local state = require("telescope.state")
8
8
9
9
local utils = require (" telescope-orgmode.utils" )
10
10
11
- local orgmode = require (" orgmode" )
12
- local Files = require (" orgmode.parser.files" )
13
- local Capture = require (" orgmode.capture" )
14
- local Range = require (" orgmode.parser.range" )
11
+ local api = require (" orgmode.api" )
15
12
16
13
return function (opts )
17
14
opts = opts or {}
18
15
19
- -- TODO: this should be included in return from Files.get_current_file
20
- local is_capture = vim .F .npcall (vim .api .nvim_buf_get_var , 0 , " org_capture" )
21
-
22
- local src_file = Files .get_current_file ()
23
- -- In capture, refile top level heading even if cursor closer to a subheading
24
- local src_item = is_capture and src_file :get_headlines ()[1 ] or src_file :get_closest_headline ()
25
- local src_lines = src_file :get_headline_lines (src_item )
16
+ local closest_headline = api .current ():get_closest_headline ()
26
17
27
18
local function refile (prompt_bufnr )
28
19
local entry = action_state .get_selected_entry ()
29
20
actions .close (prompt_bufnr )
30
21
31
- local dst_file = entry .value .file
32
- local dst_headline = entry .value .headline
33
- if dst_headline then
34
- -- NOTE: adapted from Capture:refile_to_headline
35
- local is_same_file = dst_file .filename == src_item .root .filename
36
- src_lines = Capture :_adapt_headline_level (src_item , dst_headline .level , is_same_file )
37
- local refile_opts = {
38
- file = dst_file .filename ,
39
- lines = src_lines ,
40
- item = src_item ,
41
- range = Range .from_line (dst_headline .position .end_line ),
42
- headline = dst_headline .title ,
43
- }
44
- local refiled = Capture :_refile_to (refile_opts )
45
- if not refiled then
46
- return false
47
- end
48
- else
49
- Capture :_refile_to_end (dst_file .filename , src_lines , src_item )
50
- end
22
+ -- Refile to the file by default
23
+ local destination = entry .value .file
51
24
52
- if is_capture then
53
- orgmode .action (" capture.kill" )
25
+ -- Refile to a specific heading if is set
26
+ if entry .value .headline then
27
+ destination = entry .value .headline
54
28
end
29
+
30
+ return api .refile ({
31
+ source = closest_headline ,
32
+ destination = destination ,
33
+ })
55
34
end
56
35
57
36
local function gen_depth_toggle (opts , prompt_bufnr )
0 commit comments