From fdcdfca2a68dddf107f78fab7d8c6eb23c54237d Mon Sep 17 00:00:00 2001 From: Mark Sverdlov Date: Sat, 12 Jul 2025 21:39:29 +0300 Subject: [PATCH 1/2] 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]. --- lua/orgmode/org/mappings.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/orgmode/org/mappings.lua b/lua/orgmode/org/mappings.lua index fb23ecf4e..65fdb012e 100644 --- a/lua/orgmode/org/mappings.lua +++ b/lua/orgmode/org/mappings.lua @@ -813,7 +813,7 @@ function OrgMappings:move_subtree_up() 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 + 1, pos[2]) + vim.fn.cursor(target_line + 1, pos[3]) if foldclosed > -1 and vim.fn.foldclosed('.') == -1 then vim.cmd([[norm!zc]]) end @@ -830,7 +830,7 @@ function OrgMappings:move_subtree_down() 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]) + vim.fn.cursor(target_line + range.start_line - range.end_line, pos[3]) if foldclosed > -1 and vim.fn.foldclosed('.') == -1 then vim.cmd([[norm!zc]]) end From 5bfa7f3b0fd0b780cb77172f7e54cc842e56986a Mon Sep 17 00:00:00 2001 From: Mark Sverdlov Date: Sat, 12 Jul 2025 21:47:07 +0300 Subject: [PATCH 2/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. --- lua/orgmode/org/mappings.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/orgmode/org/mappings.lua b/lua/orgmode/org/mappings.lua index 65fdb012e..fe747d5c2 100644 --- a/lua/orgmode/org/mappings.lua +++ b/lua/orgmode/org/mappings.lua @@ -814,7 +814,7 @@ function OrgMappings:move_subtree_up() 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 + 1, pos[3]) - if foldclosed > -1 and vim.fn.foldclosed('.') == -1 then + if foldclosed > -1 and vim.fn.foldlevel('.') > 0 and vim.fn.foldclosed('.') == -1 then vim.cmd([[norm!zc]]) end end @@ -831,7 +831,7 @@ function OrgMappings:move_subtree_down() 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[3]) - if foldclosed > -1 and vim.fn.foldclosed('.') == -1 then + if foldclosed > -1 and vim.fn.foldlevel('.') > 0 and vim.fn.foldclosed('.') == -1 then vim.cmd([[norm!zc]]) end end