mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
terminal: handle &confirm and :confirm on unloading (#8726)
Show a proper confirmation dialog when trying to unload a terminal buffer while the confirm option is set or when :confirm is used. Fixes https://github.com/neovim/neovim/issues/4651
This commit is contained in:
parent
56065bbdc6
commit
01570f1ff3
@ -1172,14 +1172,21 @@ do_buffer (
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (buf->terminal) {
|
if (buf->terminal) {
|
||||||
EMSG2(_("E89: %s will be killed(add ! to override)"),
|
if (p_confirm || cmdmod.confirm) {
|
||||||
(char *)buf->b_fname);
|
if (!dialog_close_terminal(buf)) {
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
EMSG2(_("E89: %s will be killed(add ! to override)"),
|
||||||
|
(char *)buf->b_fname);
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
EMSGN(_("E89: No write since last change for buffer %" PRId64
|
EMSGN(_("E89: No write since last change for buffer %" PRId64
|
||||||
" (add ! to override)"),
|
" (add ! to override)"),
|
||||||
buf->b_fnum);
|
buf->b_fnum);
|
||||||
|
return FAIL;
|
||||||
}
|
}
|
||||||
return FAIL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1339,6 +1339,22 @@ void dialog_changed(buf_T *buf, int checkall)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Ask the user whether to close the terminal buffer or not.
|
||||||
|
///
|
||||||
|
/// @param buf The terminal buffer.
|
||||||
|
/// @return bool Whether to close the buffer or not.
|
||||||
|
bool dialog_close_terminal(buf_T *buf)
|
||||||
|
{
|
||||||
|
char_u buff[DIALOG_MSG_SIZE];
|
||||||
|
|
||||||
|
dialog_msg(buff, _("Close \"%s\"?"),
|
||||||
|
(buf->b_fname != NULL) ? buf->b_fname : (char_u *)"?");
|
||||||
|
|
||||||
|
int ret = vim_dialog_yesnocancel(VIM_QUESTION, NULL, buff, 1);
|
||||||
|
|
||||||
|
return (ret == VIM_YES) ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
/// Return true if the buffer "buf" can be abandoned, either by making it
|
/// Return true if the buffer "buf" can be abandoned, either by making it
|
||||||
/// hidden, autowriting it or unloading it.
|
/// hidden, autowriting it or unloading it.
|
||||||
bool can_abandon(buf_T *buf, int forceit)
|
bool can_abandon(buf_T *buf, int forceit)
|
||||||
|
@ -201,6 +201,28 @@ describe('terminal buffer', function()
|
|||||||
feed([[<C-\><C-n>]])
|
feed([[<C-\><C-n>]])
|
||||||
feed_command('bdelete!')
|
feed_command('bdelete!')
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
describe('handles confirmations', function()
|
||||||
|
it('with :confirm', function()
|
||||||
|
feed_command('terminal')
|
||||||
|
feed('<c-\\><c-n>')
|
||||||
|
feed_command('confirm bdelete')
|
||||||
|
screen:expect('Close "term://', nil, true, nil, true)
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('with &confirm', function()
|
||||||
|
feed_command('terminal')
|
||||||
|
feed('<c-\\><c-n>')
|
||||||
|
feed_command('bdelete')
|
||||||
|
screen:expect('E89', nil, true, nil, true)
|
||||||
|
feed('<cr>')
|
||||||
|
eq('terminal', eval('&buftype'))
|
||||||
|
feed_command('set confirm | bdelete')
|
||||||
|
screen:expect('Close "term://', nil, true, nil, true)
|
||||||
|
feed('y')
|
||||||
|
neq('terminal', eval('&buftype'))
|
||||||
|
end)
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe('No heap-buffer-overflow when using', function()
|
describe('No heap-buffer-overflow when using', function()
|
||||||
|
Loading…
Reference in New Issue
Block a user