fix(tui): don't call tinput_init() twice (#36386)

This commit is contained in:
zeertzjq
2025-10-30 11:06:30 +08:00
committed by GitHub
parent c75f547839
commit 69bddc089f
3 changed files with 47 additions and 1 deletions

View File

@@ -125,6 +125,7 @@ static PMap(int) kitty_key_map = MAP_INIT;
void tinput_init(TermInput *input, Loop *loop, TerminfoEntry *ti)
{
assert(input->loop == NULL);
input->loop = loop;
input->paste = 0;
input->in_fd = STDIN_FILENO;
@@ -163,6 +164,7 @@ void tinput_destroy(TermInput *input)
uv_close((uv_handle_t *)&input->bg_query_timer, NULL);
rstream_may_close(&input->read_stream);
termkey_destroy(input->tk);
input->loop = NULL;
}
void tinput_start(TermInput *input)

View File

@@ -596,7 +596,9 @@ static void tui_terminal_start(TUIData *tui)
{
tui->print_attr_id = -1;
terminfo_start(tui);
tinput_init(&tui->input, &main_loop, &tui->ti);
if (tui->input.loop == NULL) {
tinput_init(&tui->input, &main_loop, &tui->ti);
}
tui_guess_size(tui);
tinput_start(&tui->input);
}

View File

@@ -53,6 +53,48 @@ describe('TUI', function()
end
screen:expect({ any = vim.pesc('[Process exited 1]'), unchanged = true })
end)
it('suspending does not crash or hang', function()
clear()
local screen = tt.setup_child_nvim({ '--clean', '--cmd', 'set notermguicolors' })
local s0 = [[
^ |
~ |*3
{2:[No Name] 0,0-1 All}|
|
{5:-- TERMINAL --} |
]]
screen:expect(s0)
feed_data(':')
local s1 = [[
|
~ |*3
{2:[No Name] 0,0-1 All}|
:^ |
{5:-- TERMINAL --} |
]]
screen:expect(s1)
feed_data('suspend\r')
if is_os('win') then -- no-op on Windows
screen:expect([[
^ |
~ |*3
{2:[No Name] 0,0-1 All}|
:suspend |
{5:-- TERMINAL --} |
]])
else -- resuming works on other platforms
screen:expect([[
^ |
|*5
{5:-- TERMINAL --} |
]])
exec_lua([[vim.uv.kill(vim.fn.jobpid(vim.bo.channel), 'sigcont')]])
screen:expect(s0)
end
feed_data(':')
screen:expect(s1)
end)
end)
describe('TUI :detach', function()