@@ -5,7 +5,6 @@ local ConfigViews = require("noice.config.views")
5
5
local Util = require (" noice.util" )
6
6
local Object = require (" nui.object" )
7
7
local Format = require (" noice.text.format" )
8
- local Markdown = require (" noice.text.markdown" )
9
8
10
9
--- @class NoiceViewBaseOptions
11
10
--- @field buf_options ? table<string,any>
@@ -138,8 +137,10 @@ function View:display()
138
137
139
138
self ._visible = true
140
139
else
140
+ if self ._visible then
141
+ self :hide ()
142
+ end
141
143
self ._visible = false
142
- self :hide ()
143
144
end
144
145
return true
145
146
end
@@ -188,12 +189,17 @@ function View:content()
188
189
end
189
190
190
191
function View :set_win_options (win )
191
- vim .api . nvim_win_set_option ( win , " winbar" , " " )
192
- vim .api . nvim_win_set_option ( win , " foldenable" , false )
192
+ vim .wo [ win ]. winbar = " "
193
+ vim .wo [ win ]. foldenable = false
193
194
if self ._opts .win_options then
194
195
require (" nui.utils" )._ .set_win_options (win , self ._opts .win_options )
195
196
end
196
- vim .api .nvim_win_set_cursor (win , { 1 , 0 })
197
+ vim .schedule (function ()
198
+ vim .api .nvim_win_set_cursor (win , { 1 , 0 })
199
+ vim .api .nvim_win_call (win , function ()
200
+ vim .cmd ([[ noautocmd silent! normal! zt]] )
201
+ end )
202
+ end )
197
203
end
198
204
199
205
--- @param buf number buffer number
@@ -218,6 +224,13 @@ function View:render(buf, opts)
218
224
vim .api .nvim_buf_clear_namespace (buf , Config .ns , linenr - 1 , - 1 )
219
225
vim .b [buf ].messages = {}
220
226
227
+ --- @type number ?
228
+ local win = vim .fn .bufwinid (buf )
229
+ if win == - 1 then
230
+ win = nil
231
+ end
232
+ local cursor = win and vim .api .nvim_win_get_cursor (win )
233
+
221
234
if not opts .highlight then
222
235
vim .api .nvim_buf_set_lines (buf , linenr - 1 , - 1 , false , {})
223
236
end
@@ -230,6 +243,11 @@ function View:render(buf, opts)
230
243
end
231
244
linenr = linenr + m :height ()
232
245
end
246
+
247
+ if cursor then
248
+ -- restore cursor
249
+ pcall (vim .api .nvim_win_set_cursor , win , cursor )
250
+ end
233
251
end
234
252
235
253
return View
0 commit comments