From c64c1279f30da2ca1c5b19c53b2cbbd8407d02f9 Mon Sep 17 00:00:00 2001 From: Furkan Sahin Date: Wed, 12 Mar 2025 18:16:06 -0400 Subject: [PATCH] fix(windows): fix folds getting messed up when changing todo state Problem: when changing todo state in an orgfile using `orgmode-org_todo_prev` or `orgmode-org_todo_next`, the last line in the fold seems to exit the fold. This happens when using `nvim_buf_set_text` to change the TODO state. It also happens when using `nvim_buf_get_lines` to add the closing timestamp. I think it's a neovim issue. https://github.com/neovim/neovim/issues/30352 might be related. Solution: `:help zX` Run fold recomputation. `zx` runs `zv` which opens the fold after recomputation. `zX` does not this do. Changing TODO state should not change fold state. --- lua/orgmode/files/file.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/orgmode/files/file.lua b/lua/orgmode/files/file.lua index 30046d3a6..d9aea8bae 100644 --- a/lua/orgmode/files/file.lua +++ b/lua/orgmode/files/file.lua @@ -492,6 +492,7 @@ function OrgFile:set_node_text(node, text, front_trim) end_col = vim.api.nvim_buf_get_lines(bufnr, end_row, end_row + 1, false)[1]:len() end local ok = pcall(vim.api.nvim_buf_set_text, bufnr, start_row, start_col, end_row, end_col, replacement) + vim.cmd('normal! zX') -- Refresh folds return ok end