From 9d2ad7392fa6b0be8198fe06909e1b1577082b20 Mon Sep 17 00:00:00 2001 From: Leonardo Laurindo Date: Sat, 15 Aug 2026 10:57:28 -0300 Subject: [PATCH] refactor: replace win_execute string injection with nvim_win_call in _adjust_scroll The top-fill and bottom-scroll adjustments previously built Vimscript/Lua strings at runtime and evaluated them via win_execute, e.g. 'win_execute(winid, "lua vim.fn.winrestview({topfill=...})")'. This is eval-style and fragile to internal changes. Replace both with direct vim.api.nvim_win_call calls: - winrestview({ topfill = count }) for the top case - vim.cmd.normal(needed .. "\5") for the bottom case The N scroll itself is retained: winrestview topline clamps to the last buffer line and cannot reveal past-EOF virt_lines, so CTRL-E remains the only stable mechanism. No behavior change. --- lua/inline-diff/init.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lua/inline-diff/init.lua b/lua/inline-diff/init.lua index d1ed50b..7653aa7 100644 --- a/lua/inline-diff/init.lua +++ b/lua/inline-diff/init.lua @@ -137,7 +137,9 @@ function M._adjust_scroll(bufnr, ns) if m[4].virt_lines and m[4].virt_lines_above then local count = #m[4].virt_lines if view.topfill ~= count then - vim.fn.win_execute(winid, "lua vim.fn.winrestview({topfill=" .. count .. "})") + vim.api.nvim_win_call(winid, function() + vim.fn.winrestview({ topfill = count }) + end) end break end @@ -173,7 +175,9 @@ function M._adjust_scroll(bufnr, ns) local space = win_height - last_line_row - last_line_height local needed = count - space if needed > 0 then - vim.fn.win_execute(winid, "normal! " .. needed .. "\5") -- N + vim.api.nvim_win_call(winid, function() + vim.cmd.normal(needed .. "\5") -- N + end) end end end