Skip to content

Commit

Permalink
fix(cmdline): better and safer way to trigger redraw during cmdpreview
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Oct 15, 2023
1 parent b990101 commit 02ed6d4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 16 deletions.
1 change: 0 additions & 1 deletion lua/noice/util/ffi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ function M.load()
int hl_blend;
} HlAttrs;
HlAttrs syn_attr2entry(int attr);
void update_screen();
bool cmdpreview;
]]
)
Expand Down
17 changes: 7 additions & 10 deletions lua/noice/util/hacks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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(" <bs>")
end

---@type string?
Expand Down
5 changes: 0 additions & 5 deletions tests/util/ffi_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 02ed6d4

Please sign in to comment.