fix: make :restart respect 'confirm' option #36531

When 'confirm' is set and there are unsaved buffers,
:restart now prompts before quitting, matching the behavior of :quit.
This commit is contained in:
alf171
2025-11-16 14:08:38 -05:00
committed by GitHub
parent e4e6605943
commit d464dffd2f
2 changed files with 22 additions and 3 deletions

View File

@@ -4905,11 +4905,22 @@ static void ex_restart(exarg_T *eap)
});
set_vim_var_list(VV_ARGV, argv_cpy);
}
char *quit_cmd = (eap->do_ecmd_cmd) ? eap->do_ecmd_cmd : "qall!";
Error err = ERROR_INIT;
if ((cmdmod.cmod_flags & CMOD_CONFIRM) && check_changed_any(false, false)) {
bool confirm = (p_confirm || (cmdmod.cmod_flags & CMOD_CONFIRM));
if (confirm && check_changed_any(false, false)) {
return;
}
char *quit_cmd;
if (eap->do_ecmd_cmd) {
quit_cmd = eap->do_ecmd_cmd;
} else if (confirm) {
quit_cmd = "qall";
} else {
quit_cmd = "qall!";
}
Error err = ERROR_INIT;
restarting = true;
nvim_command(cstr_as_string(quit_cmd), &err);
if (ERROR_SET(&err)) {

View File

@@ -378,6 +378,14 @@ describe('TUI :restart', function()
tt.feed_data('C\013')
screen:expect({ any = vim.pesc('[No Name]') })
-- Check :restart respects 'confirm' option.
tt.feed_data(':set confirm\013')
tt.feed_data(':restart\013')
screen:expect({ any = vim.pesc('Save changes to "Untitled"?') })
tt.feed_data('C\013')
screen:expect({ any = vim.pesc('[No Name]') })
tt.feed_data(':set noconfirm\013')
-- Check ":confirm restart <cmd>" on a modified buffer.
tt.feed_data(':confirm restart echo "Hello"\013')
screen:expect({ any = vim.pesc('Save changes to "Untitled"?') })