Skip to content

Fix refiling to current buffer (#644) #647

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -319,8 +328,8 @@ function Capture:_refile_to(opts)
target_line = headline.range.end_line
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