diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index 22dd51b249..cfd71a114e 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -223,12 +223,11 @@ void dialog_changed(buf_T *buf, bool checkall) } } - // restore to empty when write failed + // restore to empty when write failed or was cancelled if (empty_bufname) { buf->b_fname = NULL; XFREE_CLEAR(buf->b_ffname); XFREE_CLEAR(buf->b_sfname); - unchanged(buf, true, false); } } else if (ret == VIM_NO) { unchanged(buf, true, false); diff --git a/test/old/testdir/test_buffer.vim b/test/old/testdir/test_buffer.vim index 997a952a14..e71907ff39 100644 --- a/test/old/testdir/test_buffer.vim +++ b/test/old/testdir/test_buffer.vim @@ -344,6 +344,28 @@ func Test_goto_buf_with_confirm() close! endfunc +" Test for issue #20132: when saving an unnamed buffer fails the modified +" flag must be kept, otherwise the buffer is silently discarded. +func Test_dialog_changed_keep_modified_on_write_fail() + CheckUnix + CheckNotGui + CheckFeature dialog_con + CheckNotFeature dialog_con_gui + CheckNotRoot + + call writefile(['existing'], 'Untitled', 'D') + call setfperm('Untitled', 'r--r--r--') + + new + call setline(1, 'test') + call feedkeys('y', 'L') + silent! confirm bdel + call assert_true(&modified) + call assert_equal(['existing'], readfile('Untitled')) + + bw! +endfunc + " Test for splitting buffer with 'switchbuf' func Test_buffer_switchbuf() new Xswitchbuf