From 57ca4e817d3750dfd8cccade2ba1bfbce76a452e Mon Sep 17 00:00:00 2001 From: troiganto Date: Thu, 30 Jan 2025 16:16:34 +0100 Subject: [PATCH] fix(attach): unset_directory couldn't switch from DIR to ID directory --- lua/orgmode/attach/core.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lua/orgmode/attach/core.lua b/lua/orgmode/attach/core.lua index 58daf30c2..59022b8c4 100644 --- a/lua/orgmode/attach/core.lua +++ b/lua/orgmode/attach/core.lua @@ -308,7 +308,13 @@ end function AttachCore:unset_directory(node, opts) local old_dir = self:get_dir(node, true) node:set_dir() - local new_dir = self:get_dir(node, true) -- new dir potentially via parent nodes + -- After removal, there might be a new DIR directory via inheritance. + local new_dir = self:get_dir_or_nil(node, true) + if not new_dir then + -- There is no parent node with a DIR property. Switch back to ID-based + -- directory. + new_dir = node:id_dir_get_or_create() + end -- Ordering matters here: both `opts` should be evaluated before the -- operations (copy if desired, delete if desired) start. ---@param do_copy? boolean