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 messages are more concise:
• "Error detected while processing:" changed to "Error in:". • "Error detected while processing:" changed to "Error in:".
• "Error executing Lua:" changed to "Lua:". • "Error executing Lua:" changed to "Lua:".
• |:restart| detaches the embedded server from the UI and then restarts • |:restart| detaches the embedded server from the UI and then restarts it.
it.
VIMSCRIPT VIMSCRIPT

View File

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