From af82f36108ce5bd481ea469cd44df94bff3d0444 Mon Sep 17 00:00:00 2001 From: luukvbaal Date: Sat, 7 Jun 2025 11:24:24 +0200 Subject: [PATCH] fix(api): update topline when flushing with nvim__redraw() (#34346) Problem: nvim__redraw may update the screen with an invalid topline. Solution: Update the topline before calling `update_screen()` (as :redraw does). --- src/nvim/api/vim.c | 2 ++ test/functional/api/vim_spec.lua | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 7d9239ec12..7f8aa08e40 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -2376,6 +2376,8 @@ void nvim__redraw(Dict(redraw) *opts, Error *err) // Redraw pending screen updates when explicitly requested or when determined // that it is necessary to properly draw other requested components. if (opts->flush && !cmdpreview) { + validate_cursor(curwin); + update_topline(curwin); update_screen(); } diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 7dae67c723..0567aa411c 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -5674,4 +5674,32 @@ describe('API', function() n.assert_alive() end) + + it('nvim__redraw updates topline', function() + local screen = Screen.new(40, 8) + fn.setline(1, fn.range(100)) + feed(':call getchar()') + fn.cursor(50, 1) + screen:expect([[ + 0 | + 1 | + 2 | + 3 | + 4 | + 5 | + 6 | + ^:call getchar() | + ]]) + api.nvim__redraw({ flush = true }) + screen:expect([[ + 46 | + 47 | + 48 | + 49 | + 50 | + 51 | + 52 | + ^:call getchar() | + ]]) + end) end)