fix: refile closes the window when in capture mode

fixes https://github.com/joaomsa/telescope-orgmode.nvim/issues/4
This commit is contained in:
Lyz 2023-11-28 03:37:37 +01:00
parent eabff061c3
commit f577d3ba11
No known key found for this signature in database
GPG Key ID: 6C7D7C1612CDE02F

View File

@ -8,8 +8,10 @@ local state = require("telescope.state")
local utils = require('telescope-orgmode.utils') local utils = require('telescope-orgmode.utils')
local orgmode = require('orgmode')
local Files = require('orgmode.parser.files') local Files = require('orgmode.parser.files')
local Capture = require('orgmode.capture') local Capture = require('orgmode.capture')
local Range = require('orgmode.parser.range')
return function(opts) return function(opts)
opts = opts or {} opts = opts or {}
@ -36,17 +38,23 @@ return function(opts)
local is_same_file = dst_file.filename == src_item.root.filename local is_same_file = dst_file.filename == src_item.root.filename
src_lines = src_item:demote(dst_headline.level - src_item.level + 1, true, not is_same_file) src_lines = src_item:demote(dst_headline.level - src_item.level + 1, true, not is_same_file)
end end
local refiled = Capture:_refile_to(dst_file.filename, src_lines, src_item, dst_headline.position.end_line) refile_opts = {
file = dst_file.filename,
lines = src_lines,
item = src_item,
range = Range.from_line(dst_headline.position.end_line),
headline = dst_headline.position.end_line,
}
local refiled = Capture:_refile_to(refile_opts)
if not refiled then if not refiled then
return false return false
end end
--utils.echo_info(string.format('Wrote %s', dst_file.filename))
else else
Capture:_refile_to_end(dst_file.filename, src_lines, src_item) Capture:_refile_to_end(dst_file.filename, src_lines, src_item)
end end
if is_capture then if is_capture then
Capture:kill() orgmode.action('capture.kill')
end end
end end