diff --git a/lua/noice/view/init.lua b/lua/noice/view/init.lua index b79dcff..6d12330 100644 --- a/lua/noice/view/init.lua +++ b/lua/noice/view/init.lua @@ -5,7 +5,6 @@ local ConfigViews = require("noice.config.views") local Util = require("noice.util") local Object = require("nui.object") local Format = require("noice.text.format") -local Markdown = require("noice.text.markdown") ---@class NoiceViewBaseOptions ---@field buf_options? table @@ -138,8 +137,10 @@ function View:display() self._visible = true else + if self._visible then + self:hide() + end self._visible = false - self:hide() end return true end @@ -188,12 +189,17 @@ function View:content() end function View:set_win_options(win) - vim.api.nvim_win_set_option(win, "winbar", "") - vim.api.nvim_win_set_option(win, "foldenable", false) + vim.wo[win].winbar = "" + vim.wo[win].foldenable = false if self._opts.win_options then require("nui.utils")._.set_win_options(win, self._opts.win_options) end - vim.api.nvim_win_set_cursor(win, { 1, 0 }) + vim.schedule(function() + vim.api.nvim_win_set_cursor(win, { 1, 0 }) + vim.api.nvim_win_call(win, function() + vim.cmd([[noautocmd silent! normal! zt]]) + end) + end) end ---@param buf number buffer number @@ -218,6 +224,13 @@ function View:render(buf, opts) vim.api.nvim_buf_clear_namespace(buf, Config.ns, linenr - 1, -1) vim.b[buf].messages = {} + ---@type number? + local win = vim.fn.bufwinid(buf) + if win == -1 then + win = nil + end + local cursor = win and vim.api.nvim_win_get_cursor(win) + if not opts.highlight then vim.api.nvim_buf_set_lines(buf, linenr - 1, -1, false, {}) end @@ -230,6 +243,11 @@ function View:render(buf, opts) end linenr = linenr + m:height() end + + if cursor then + -- restore cursor + pcall(vim.api.nvim_win_set_cursor, win, cursor) + end end return View diff --git a/lua/noice/view/nui.lua b/lua/noice/view/nui.lua index 3aaf2f5..34c9381 100644 --- a/lua/noice/view/nui.lua +++ b/lua/noice/view/nui.lua @@ -274,9 +274,9 @@ function NuiView:show() if not self._nui.winid then return end - self:set_win_options(self._nui.winid) self:tag() if not self._visible then + self:set_win_options(self._nui.winid) self:update_layout() self:smart_move() end