fix(tui): handle cursor visibility properly (#26091)

The test is for the case without 'termsync' because libvterm doesn't
support synchronized output, and it passes without this PR.
This commit is contained in:
zeertzjq 2023-11-17 22:13:30 +08:00 committed by GitHub
parent 677be4bdd2
commit ad867fee26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 10 deletions

View File

@ -1158,14 +1158,6 @@ void tui_set_mode(TUIData *tui, ModeShape mode)
unibi_out_ext(tui, tui->unibi_ext.reset_cursor_color);
}
if (tui->want_invisible && !tui->is_invisible) {
unibi_out(tui, unibi_cursor_invisible);
tui->is_invisible = true;
} else if (!tui->want_invisible && tui->is_invisible) {
unibi_out(tui, unibi_cursor_normal);
tui->is_invisible = false;
}
int shape;
switch (c.shape) {
case SHAPE_BLOCK:
@ -1305,8 +1297,9 @@ static void tui_flush_start(TUIData *tui)
if (tui->sync_output && tui->unibi_ext.sync != -1) {
UNIBI_SET_NUM_VAR(tui->params[0], 1);
unibi_out_ext(tui, tui->unibi_ext.sync);
} else {
} else if (!tui->is_invisible) {
unibi_out(tui, unibi_cursor_invisible);
tui->is_invisible = true;
}
}
@ -1318,8 +1311,14 @@ static void tui_flush_end(TUIData *tui)
if (tui->sync_output && tui->unibi_ext.sync != -1) {
UNIBI_SET_NUM_VAR(tui->params[0], 0);
unibi_out_ext(tui, tui->unibi_ext.sync);
} else if (!tui->busy && !tui->want_invisible) {
}
bool should_invisible = tui->busy || tui->want_invisible;
if (tui->is_invisible && !should_invisible) {
unibi_out(tui, unibi_cursor_normal);
tui->is_invisible = false;
} else if (!tui->is_invisible && should_invisible) {
unibi_out(tui, unibi_cursor_invisible);
tui->is_invisible = true;
}
}

View File

@ -1785,6 +1785,31 @@ describe('TUI', function()
{3:-- TERMINAL --} |
]])
end)
it('supports hiding cursor', function()
child_session:request('nvim_command',
"let g:id = jobstart([v:progpath, '--clean', '--headless'])")
feed_data(':call jobwait([g:id])\n')
screen:expect([[
|
{4:~ }|
{4:~ }|
{4:~ }|
{5:[No Name] }|
:call jobwait([g:id]) |
{3:-- TERMINAL --} |
]])
feed_data('\003')
screen:expect([[
{1: } |
{4:~ }|
{4:~ }|
{4:~ }|
{5:[No Name] }|
Type :qa and press <Enter> to exit Nvim |
{3:-- TERMINAL --} |
]])
end)
end)
describe('TUI', function()