Skip to content

Commit

Permalink
fix: preserve folding when moving subtree
Browse files Browse the repository at this point in the history
To be consistent with promotion and demotion commands, we preserve the
folding state also when moving a subtree.
  • Loading branch information
seflue committed Jun 13, 2024
1 parent e6e9763 commit 4d869da
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lua/orgmode/org/mappings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -763,9 +763,13 @@ function OrgMappings:move_subtree_up()
end
local range = item:get_range()
local target_line = prev_headline:get_range().start_line - 1
local foldclosed = vim.fn.foldclosed('.')
vim.cmd(string.format(':%d,%dmove %d', range.start_line, range.end_line, target_line))
local pos = vim.fn.getcurpos()
vim.fn.cursor(prev_headline:get_range().start_line, pos[2])
vim.fn.cursor(target_line + 1, pos[2])
if foldclosed > -1 and vim.fn.foldclosed('.') == -1 then
vim.cmd([[norm!zc]])
end
end

function OrgMappings:move_subtree_down()
Expand All @@ -776,9 +780,13 @@ function OrgMappings:move_subtree_down()
end
local range = item:get_range()
local target_line = next_headline:get_range().end_line
local foldclosed = vim.fn.foldclosed('.')
vim.cmd(string.format(':%d,%dmove %d', range.start_line, range.end_line, target_line))
local pos = vim.fn.getcurpos()
vim.fn.cursor(target_line + range.start_line - range.end_line, pos[2])
if foldclosed > -1 and vim.fn.foldclosed('.') == -1 then
vim.cmd([[norm!zc]])
end
end

function OrgMappings:show_help(type)
Expand Down

0 comments on commit 4d869da

Please sign in to comment.