From 02ed6d4c0c1e4d21fc4e79bbe54961023ee9badb Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Sun, 15 Oct 2023 21:12:25 +0200 Subject: [PATCH] fix(cmdline): better and safer way to trigger redraw during cmdpreview --- lua/noice/util/ffi.lua | 1 - lua/noice/util/hacks.lua | 17 +++++++---------- tests/util/ffi_spec.lua | 5 ----- 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/lua/noice/util/ffi.lua b/lua/noice/util/ffi.lua index 2c5cc912..d6c11f63 100644 --- a/lua/noice/util/ffi.lua +++ b/lua/noice/util/ffi.lua @@ -16,7 +16,6 @@ function M.load() int hl_blend; } HlAttrs; HlAttrs syn_attr2entry(int attr); - void update_screen(); bool cmdpreview; ]] ) diff --git a/lua/noice/util/hacks.lua b/lua/noice/util/hacks.lua index e781fcd3..c7fb8cdb 100644 --- a/lua/noice/util/hacks.lua +++ b/lua/noice/util/hacks.lua @@ -225,18 +225,15 @@ function M.fix_cmp() end) end -local was_in_cmdline = false function M.cmdline_force_redraw() - local ffi = require("noice.util.ffi") - local pos = vim.fn.getcmdpos() - local in_cmdline = pos < #vim.fn.getcmdline() + 1 - if ffi.cmdpreview and (in_cmdline or was_in_cmdline) then - was_in_cmdline = in_cmdline - -- HACK: this will trigger redraw during substitute and cmdpreview, - -- but when moving the cursor, the screen will be cleared until - -- a new character is entered - ffi.update_screen() + if not require("noice.util.ffi").cmdpreview then + return end + + -- HACK: this will trigger redraw during substitute and cmdpreview, + -- but when moving the cursor, the screen will be cleared until + -- a new character is entered + vim.api.nvim_input(" ") end ---@type string? diff --git a/tests/util/ffi_spec.lua b/tests/util/ffi_spec.lua index 2491cd71..09978dd1 100644 --- a/tests/util/ffi_spec.lua +++ b/tests/util/ffi_spec.lua @@ -4,9 +4,4 @@ describe("ffi", function() it("cmdpreview is false", function() assert(lazy("noice.util.ffi").cmdpreview == false) end) - it("update_screen() doesn't error", function() - assert.is_not.errors(function() - lazy("noice.util.ffi").update_screen() - end) - end) end)