Skip to content

Commit

Permalink
fix(cmdline): yet another work-around that no longer temporarily chan…
Browse files Browse the repository at this point in the history
…ges the cmdline
  • Loading branch information
folke committed May 16, 2024
1 parent fff989f commit 68b9c53
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
12 changes: 0 additions & 12 deletions lua/noice/ui/cmdline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ end

---@type NoiceCmdline[]
M.cmdlines = {}
M.skipped = false

function M.on_show(event, content, pos, firstc, prompt, indent, level)
local c = Cmdline({
Expand All @@ -169,13 +168,6 @@ function M.on_show(event, content, pos, firstc, prompt, indent, level)
level = level,
})

-- This was triggered by a force redraw, so skip it
if c:get():find(Hacks.SPECIAL, 1, true) then
M.skipped = true
return
end
M.skipped = false

local last = M.cmdlines[level] and M.cmdlines[level].state
if not vim.deep_equal(c.state, last) then
M.active = c
Expand All @@ -198,9 +190,6 @@ function M.on_hide(_, level)
end

function M.on_pos(_, pos, level)
if M.skipped then
return
end
local c = M.cmdlines[level]
if c and c.state.pos ~= pos then
M.cmdlines[level].state.pos = pos
Expand All @@ -219,7 +208,6 @@ 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
19 changes: 11 additions & 8 deletions lua/noice/util/hacks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function M.enable()
M.fix_redraw()
M.fix_cmp()
M.fix_vim_sleuth()
M.fix_cmdpreview()

-- Hacks for Neovim < 0.10
if vim.fn.has("nvim-0.10") == 0 then
Expand Down Expand Up @@ -241,14 +242,16 @@ function M.fix_cmp()
end)
end

M.SPECIAL = "Þ"
function M.cmdline_force_redraw()
if not require("noice.util.ffi").cmdpreview then
return
end

-- HACK: this will trigger redraw during substitute and cmdpreview
vim.api.nvim_feedkeys(M.SPECIAL .. Util.BS, "n", true)
function M.fix_cmdpreview()
vim.api.nvim_create_autocmd("CmdlineChanged", {
group = M.group,
callback = function()
local ffi = require("noice.util.ffi")
ffi.cmdpreview = false
vim.cmd([[redraw]])
Util.try(require("noice.message.router").update)
end,
})
end

---@type string?
Expand Down

0 comments on commit 68b9c53

Please sign in to comment.