Skip to content

Commit 768b278

Browse files
authored
Fix refiling to current buffer (#644) (#647)
Fix edge case when refiling target is the current buffer, but content was captured. Co-authored-by: Sebastian Flügge <[email protected]>
1 parent e129aab commit 768b278

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lua/orgmode/capture/init.lua

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,15 @@ local function remove_buffer_empty_lines(opts)
296296
range.end_line = end_line
297297
end
298298

299+
--- Checks, if we refile a heading within one file or from one file to another.
300+
---@param opts CaptureOpts
301+
---@return boolean
302+
local function check_refile_source(opts)
303+
local source_file = opts.item and opts.item.file or utils.current_file_path()
304+
local target_file = opts.file
305+
return source_file == target_file
306+
end
307+
299308
---@private
300309
---@param opts CaptureOpts
301310
---@return boolean
@@ -319,8 +328,8 @@ function Capture:_refile_to(opts)
319328
target_line = headline.range.end_line
320329
end
321330

322-
local is_same_file = opts.file == utils.current_file_path()
323331
local item = opts.item
332+
local is_same_file = check_refile_source(opts)
324333
if item and should_adapt_headline then
325334
-- Refiling in same file just moves the lines from one position
326335
-- to another,so we need to apply demote instantly

0 commit comments

Comments
 (0)