Skip to content

Commit

Permalink
fix: call update_screen during cmdpreview to fix cursor movement. Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Nov 16, 2022
1 parent 973659e commit 23da4ed
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lua/noice/ui/cmdline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ M.position = nil
---@param line number
---@param byte number
function M.on_render(_, buf, line, byte)
Hacks.cmdline_force_redraw()
local win = vim.fn.bufwinid(buf)
if win ~= -1 then
-- FIXME: check with cmp
Expand Down Expand Up @@ -236,7 +237,6 @@ function M.update()
if cmdline then
cmdline:format(M.message)
Hacks.hide_cursor()
Hacks.cmdline_force_redraw()
Manager.add(M.message)
else
Manager.remove(M.message)
Expand Down
4 changes: 3 additions & 1 deletion lua/noice/util/ffi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ function M.setup()
} HlAttrs;
HlAttrs syn_attr2entry(int attr);
void update_screen();
bool cmdpreview;
]]
)
if not ok then
---@diagnostic disable-next-line: need-check-nil
if not ok and not err:find("redefine") then
error(err)
end
C = ffi.C
Expand Down
9 changes: 6 additions & 3 deletions lua/noice/util/hacks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,12 @@ function M.fix_cmp()
end

function M.cmdline_force_redraw()
if vim.fn.pumvisible() == 0 and vim.api.nvim_get_mode().mode == "c" and vim.fn.getcmdline():find("s/") then
-- HACK: this will trigger redraw during substitue
vim.api.nvim_input("<space><bs>")
local ffi = require("noice.util.ffi")
if ffi.cmdpreview then
-- 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()
end
end

Expand Down

0 comments on commit 23da4ed

Please sign in to comment.