Skip to content

Commit 52dcef1

Browse files
fix: avoid E490 when using move_subtree_up and move_subtree_down (#1013)
* fix: set cursor using correct coordinates The column coordinate of the cursor is given by vim.fn.getcurpos()[3], and not vim.fin.getcurpos()[2]. * fix: add condition to avoid E490 In some cases, executing org-subtree-up-or-down would causes E490 No fold found error when the functional calls vim.cmd([[norm!zc]]). This extra condition gurantees this error won't be thrown. --------- Co-authored-by: Kristijan Husak <[email protected]>
1 parent e16452b commit 52dcef1

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lua/orgmode/org/mappings.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -813,8 +813,8 @@ function OrgMappings:move_subtree_up()
813813
local foldclosed = vim.fn.foldclosed('.')
814814
vim.cmd(string.format(':%d,%dmove %d', range.start_line, range.end_line, target_line))
815815
local pos = vim.fn.getcurpos()
816-
vim.fn.cursor(target_line + 1, pos[2])
817-
if foldclosed > -1 and vim.fn.foldclosed('.') == -1 then
816+
vim.fn.cursor(target_line + 1, pos[3])
817+
if foldclosed > -1 and vim.fn.foldlevel('.') > 0 and vim.fn.foldclosed('.') == -1 then
818818
vim.cmd([[norm!zc]])
819819
end
820820
end
@@ -830,8 +830,8 @@ function OrgMappings:move_subtree_down()
830830
local foldclosed = vim.fn.foldclosed('.')
831831
vim.cmd(string.format(':%d,%dmove %d', range.start_line, range.end_line, target_line))
832832
local pos = vim.fn.getcurpos()
833-
vim.fn.cursor(target_line + range.start_line - range.end_line, pos[2])
834-
if foldclosed > -1 and vim.fn.foldclosed('.') == -1 then
833+
vim.fn.cursor(target_line + range.start_line - range.end_line, pos[3])
834+
if foldclosed > -1 and vim.fn.foldlevel('.') > 0 and vim.fn.foldclosed('.') == -1 then
835835
vim.cmd([[norm!zc]])
836836
end
837837
end

0 commit comments

Comments
 (0)