Skip to content

Commit

Permalink
feat: redraw improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jul 25, 2024
1 parent d9328ef commit 1698725
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 32 deletions.
14 changes: 0 additions & 14 deletions lua/noice/message/router.lua
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,6 @@ function M.setup()
end
end

function M.check_redraw()
if Util.is_blocking() and M._need_redraw then
-- don't do full redraw during search
if not (Util.is_search() and require("noice.ui.cmdline").real_cursor) then
-- NOTE: set to false before actually calling redraw to prevent a loop with ui
M._need_redraw = false
Util.redraw()
end
require("noice.ui.cmdline").fix_cursor()
end
end

function M.view_stats()
local views = M.get_views()
---@type table<string,number>
Expand Down Expand Up @@ -168,7 +156,6 @@ function M.update()

-- only update on changes
if M._tick == Manager.tick() then
M.check_redraw()
return
end

Expand Down Expand Up @@ -239,7 +226,6 @@ function M.update()
M._need_redraw = true
end

M.check_redraw()
M._updating = false
end

Expand Down
29 changes: 13 additions & 16 deletions lua/noice/ui/cmdline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ M.real_cursor = vim.api.nvim__redraw ~= nil
---@field prompt string
---@field indent number
---@field level number
---@field block table
---@field block? table

---@class CmdlineFormat
---@field name string
Expand Down Expand Up @@ -229,27 +229,24 @@ end
M.position = nil

function M.fix_cursor()
if not M.position then
local win = M.win()
if not win or not M.real_cursor then
return
end
local win = M.position.win
local cursor = M.position.cursor
if vim.api.nvim_win_is_valid(win) then
local height = vim.api.nvim_buf_line_count(M.position.buf)
vim.api.nvim_win_set_cursor(win, { height, cursor })
local cursor = { vim.api.nvim_buf_line_count(M.position.buf), M.position.cursor }
vim.api.nvim_win_set_cursor(win, cursor)
local leftcol = math.max(cursor[2] - vim.api.nvim_win_get_width(win) + 1, 0)
local view = vim.api.nvim_win_call(win, vim.fn.winsaveview)
if view.leftcol ~= leftcol then
vim.api.nvim_win_call(win, function()
local width = vim.api.nvim_win_get_width(win)
local leftcol = math.max(cursor - width + 1, 0)
vim.fn.winrestview({ leftcol = leftcol })
end)
if M.real_cursor then
vim.cmd.redrawstatus()
vim.api.nvim__redraw({
cursor = true,
win = win,
})
end
end
vim.api.nvim__redraw({ cursor = true, win = win })
end

function M.win()
return M.position and M.position.win and vim.api.nvim_win_is_valid(M.position.win) and M.position.win or nil
end

---@param buf number
Expand Down
25 changes: 24 additions & 1 deletion lua/noice/util/hacks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ local require = require("noice.util.lazy")

local Api = require("noice.api")
local Cmdline = require("noice.ui.cmdline")
local Router = require("noice.message.router")
local Util = require("noice.util")
local uv = vim.uv or vim.loop

-- HACK: a bunch of hacks to make Noice behave
local M = {}
Expand All @@ -19,13 +19,36 @@ function M.enable()
M.reset_augroup()
M.fix_cmp()
M.fix_vim_sleuth()
M.fix_redraw()

-- Hacks for Neovim < 0.10
if vim.fn.has("nvim-0.10") == 0 then
M.fix_incsearch()
end
end

function M.fix_redraw()
local timer = uv.new_timer()
timer:start(
0,
30,
vim.schedule_wrap(function()
if not Util.is_search() then
if vim.api.nvim__redraw then
vim.api.nvim__redraw({ flush = true, cursor = true })
else
vim.cmd.redraw()
end
end
Cmdline.fix_cursor()
end)
)
table.insert(M._disable, function()
timer:stop()
timer:close()
end)
end

function M.fix_vim_sleuth()
vim.g.sleuth_noice_heuristics = 0
end
Expand Down
1 change: 0 additions & 1 deletion lua/noice/view/backend/notify.lua
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ function NotifyView:_notify(msg)

local opts = {
title = msg.title or self._opts.title,
animate = not Util.is_blocking(),
timeout = self._opts.timeout,
replace = self._opts.replace and self.notif,
keep = function()
Expand Down

0 comments on commit 1698725

Please sign in to comment.