mirror of
https://github.com/neovim/neovim.git
synced 2026-04-21 23:05:41 +00:00
fix(ui2): callbacks reference stale message-window handles #37673
Problem: Scheduled callbacks reference potentially outdated window
handles e.g. after switching tabpage.
Solution: Use ext.wins which stores the updated window handles.
This commit is contained in:
@@ -496,10 +496,10 @@ function M.set_pos(type)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
vim.schedule(function()
|
vim.schedule(function()
|
||||||
local entered = api.nvim_get_current_win() == win
|
local entered = api.nvim_get_current_win() == ext.wins.cmd
|
||||||
cmd_on_key = nil
|
cmd_on_key = nil
|
||||||
if api.nvim_win_is_valid(win) then
|
if api.nvim_win_is_valid(ext.wins.cmd) then
|
||||||
api.nvim_win_close(win, true)
|
api.nvim_win_close(ext.wins.cmd, true)
|
||||||
end
|
end
|
||||||
ext.check_targets()
|
ext.check_targets()
|
||||||
-- Show or clear the message depending on if the pager was opened.
|
-- Show or clear the message depending on if the pager was opened.
|
||||||
@@ -566,15 +566,15 @@ function M.set_pos(type)
|
|||||||
|
|
||||||
-- Cmdwin is actually closed one event iteration later so schedule in case it was open.
|
-- Cmdwin is actually closed one event iteration later so schedule in case it was open.
|
||||||
vim.schedule(function()
|
vim.schedule(function()
|
||||||
api.nvim_set_current_win(win)
|
api.nvim_set_current_win(ext.wins.pager)
|
||||||
-- Make pager relative to cmdwin when it is opened, restore when it is closed.
|
-- Make pager relative to cmdwin when it is opened, restore when it is closed.
|
||||||
api.nvim_create_autocmd({ 'WinEnter', 'CmdwinEnter', 'CmdwinLeave' }, {
|
api.nvim_create_autocmd({ 'WinEnter', 'CmdwinEnter', 'CmdwinLeave' }, {
|
||||||
callback = function(ev)
|
callback = function(ev)
|
||||||
if api.nvim_win_is_valid(win) then
|
if api.nvim_win_is_valid(ext.wins.pager) then
|
||||||
local cfg = ev.event == 'CmdwinLeave' and config
|
local cfg = ev.event == 'CmdwinLeave' and config
|
||||||
or ev.event == 'WinEnter' and { hide = true }
|
or ev.event == 'WinEnter' and { hide = true }
|
||||||
or { relative = 'win', win = 0, row = 0, col = 0 }
|
or { relative = 'win', win = 0, row = 0, col = 0 }
|
||||||
api.nvim_win_set_config(win, cfg)
|
api.nvim_win_set_config(ext.wins.pager, cfg)
|
||||||
end
|
end
|
||||||
return ev.event == 'WinEnter'
|
return ev.event == 'WinEnter'
|
||||||
end,
|
end,
|
||||||
|
|||||||
@@ -102,11 +102,28 @@ describe('messages2', function()
|
|||||||
{1:~ }|*12
|
{1:~ }|*12
|
||||||
^R 1,1 All|
|
^R 1,1 All|
|
||||||
]])
|
]])
|
||||||
feed('-')
|
feed('-<Esc>')
|
||||||
screen:expect([[
|
screen:expect([[
|
||||||
x^ |
|
^x |
|
||||||
{1:~ }|*12
|
{1:~ }|*12
|
||||||
1,2 All|
|
1,1 All|
|
||||||
|
]])
|
||||||
|
-- Switching tabpage closes expanded cmdline #37659.
|
||||||
|
command('tabnew | echo "foo\nbar"')
|
||||||
|
screen:expect([[
|
||||||
|
{24: + [No Name] }{5: }{100:2}{5: [No Name] }{2: }{24:X}|
|
||||||
|
^ |
|
||||||
|
{1:~ }|*9
|
||||||
|
{3: }|
|
||||||
|
foo |
|
||||||
|
bar |
|
||||||
|
]])
|
||||||
|
feed('gt')
|
||||||
|
screen:expect([[
|
||||||
|
{5: + [No Name] }{24: [No Name] }{2: }{24:X}|
|
||||||
|
^x |
|
||||||
|
{1:~ }|*11
|
||||||
|
foo [+1] 1,1 All|
|
||||||
]])
|
]])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user