Skip to content

Commit

Permalink
fix: make refiling more robust
Browse files Browse the repository at this point in the history
Fix edge case when refiling target is the current buffer, but content
was captured.
  • Loading branch information
seflue committed Jan 7, 2024
1 parent 2f7907f commit e6fcced
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lua/orgmode/capture/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,15 @@ local function remove_buffer_empty_lines(opts)
range.end_line = end_line
end

--- Checks, if we refile a heading within one file or from one file to another.
---@param opts CaptureOpts
---@return boolean
local function check_refile_source(opts)
local source_file = opts.item and opts.item.file or utils.current_file_path()
local target_file = opts.file
return source_file == target_file
end

---@private
---@param opts CaptureOpts
---@return boolean
Expand All @@ -322,8 +331,8 @@ function Capture:_refile_to(opts)
target_line = -1
end

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

0 comments on commit e6fcced

Please sign in to comment.