fix(tui): make :restart use new size after terminal resize (#34282)

This commit is contained in:
zeertzjq
2025-06-03 08:18:04 +08:00
committed by GitHub
parent 304a9baebd
commit 049877d379
3 changed files with 74 additions and 86 deletions

View File

@@ -229,8 +229,7 @@ UI
• Error messages are more concise:
• "Error detected while processing:" changed to "Error in:".
• "Error executing Lua:" changed to "Lua:".
• |:restart| detaches the embedded server from the UI and then restarts
it.
• |:restart| detaches the embedded server from the UI and then restarts it.
VIMSCRIPT

View File

@@ -202,6 +202,8 @@ void ui_client_set_size(int width, int height)
ADD_C(args, INTEGER_OBJ((int)height));
rpc_send_event(ui_client_channel_id, "nvim_ui_try_resize", args);
}
tui_width = width;
tui_height = height;
}
UIClientHandler ui_client_get_redraw_handler(const char *name, size_t name_len, Error *error)

View File

@@ -34,19 +34,8 @@ local assert_log = t.assert_log
local testlog = 'Xtest-tui-log'
describe('TUI :detach', function()
before_each(function()
os.remove(testlog)
end)
teardown(function()
os.remove(testlog)
end)
it('does not stop server', function()
local job_opts = {
env = {
NVIM_LOG_FILE = testlog,
},
}
local job_opts = { env = {} }
if is_os('win') then
-- TODO(justinmk): on Windows,
@@ -83,11 +72,9 @@ describe('TUI :detach', function()
return
end
local server_super = n.clear()
local client_super = n.new_session(true)
n.clear()
finally(function()
server_super:close()
client_super:close()
n.check_close()
end)
local child_server = new_pipename()
@@ -105,15 +92,13 @@ describe('TUI :detach', function()
}, job_opts)
tt.feed_data('iHello, World')
screen:expect {
grid = [[
screen:expect([[
Hello, World^ |
{4:~ }|*3
{MATCH:No Name}
{3:-- INSERT --} |
{3:-- TERMINAL --} |
]],
}
]])
local child_session = n.connect(child_server)
finally(function()
@@ -148,15 +133,13 @@ describe('TUI :detach', function()
child_server,
}, job_opts)
screen_reattached:expect {
grid = [[
screen_reattached:expect([[
We did it, pooky^. |
{4:~ }|*3
{5:[No Name] [+] }|
|
{3:-- TERMINAL --} |
]],
}
]])
end)
end)
@@ -165,25 +148,10 @@ if t.skip(is_os('win')) then
end
describe('TUI :restart', function()
before_each(function()
os.remove(testlog)
end)
teardown(function()
os.remove(testlog)
end)
it('resets buffer to blank', function()
local server_super = n.clear()
local client_super = n.new_session(true)
local job_opts = {
env = {
NVIM_LOG_FILE = testlog,
},
}
clear()
finally(function()
server_super:close()
client_super:close()
n.check_close()
end)
local screen = tt.setup_child_nvim({
@@ -195,35 +163,44 @@ describe('TUI :restart', function()
'colorscheme vim',
'--cmd',
nvim_set .. ' notermguicolors laststatus=2 background=dark',
}, job_opts)
'--cmd',
'echo getpid()',
})
-- Check ":restart" on an unmodified buffer.
tt.feed_data('\027\027:restart\013')
screen:expect {
grid = [[
local s0 = [[
^ |
{4:~ }|*3
{5:[No Name] }|
{MATCH:%d+ +}|
{3:-- TERMINAL --} |
]]
screen:expect(s0)
tt.feed_data(':echo\013')
screen:expect([[
^ |
{4:~ }|*3
{5:[No Name] }|
|
{3:-- TERMINAL --} |
]],
}
]])
tt.feed_data('ithis will be removed')
screen:expect {
grid = [[
this will be removed^ |
-- Check ":restart" on an unmodified buffer.
tt.feed_data(':restart\013')
screen:expect(s0)
tt.feed_data('ithis will be removed\027')
screen:expect([[
this will be remove^d |
{4:~ }|*3
{5:[No Name] [+] }|
{3:-- INSERT --} |
|
{3:-- TERMINAL --} |
]],
}
]])
-- Check ":restart" on a modified buffer.
tt.feed_data('\027\027:restart\013')
screen:expect {
grid = [[
tt.feed_data(':restart\013')
screen:expect([[
this will be removed |
{5: }|
{8:E37: No write since last change} |
@@ -231,20 +208,30 @@ describe('TUI :restart', function()
{8:ame]"} |
{10:Press ENTER or type command to continue}^ |
{3:-- TERMINAL --} |
]],
}
]])
-- Check ":restart!".
tt.feed_data('\027\027:restart!\013')
screen:expect {
grid = [[
tt.feed_data(':restart!\013')
screen:expect(s0)
screen:try_resize(60, 6)
screen:expect([[
^ |
{4:~ }|*3
{4:~ }|*2
{5:[No Name] }|
|
{3:-- TERMINAL --} |
]],
}
]])
--- Check that ":restart" uses the updated size after terminal resize
tt.feed_data(':restart\013')
screen:expect([[
^ |
{4:~ }|*2
{5:[No Name] }|
{MATCH:%d+ +}|
{3:-- TERMINAL --} |
]])
end)
end)