char_u *fname;
fname = do_browse(BROWSE_SAVE, (char_u *)_("Save As"),
- NULL, NULL, NULL, NULL, buf);
+ (char_u *)"Untitled", NULL, NULL, NULL, buf);
if (fname == NULL)
return;
# ifdef FEAT_BROWSE
// May get file name, when there is none
browse_save_fname(buf);
+
+ // User cancelled the file dialog; keep the buffer modified.
+ if (buf->b_fname == NULL)
+ return;
# endif
empty_bufname = buf->b_fname == NULL ? TRUE : FALSE;
if (empty_bufname)
return;
}
- // restore to empty when write failed
+ // restore to empty when write failed or was cancelled
if (empty_bufname)
{
buf->b_fname = NULL;
VIM_CLEAR(buf->b_ffname);
VIM_CLEAR(buf->b_sfname);
- unchanged(buf, TRUE, FALSE);
}
}
else if (ret == VIM_NO)
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