diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/normal.c | 8 | ||||
-rw-r--r-- | src/nvim/testdir/test_normal.vim | 15 | ||||
-rw-r--r-- | src/nvim/undo.c | 13 |
3 files changed, 34 insertions, 2 deletions
diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 2e4cdc1fe1..4cfd11ab7c 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -7465,8 +7465,12 @@ static void nv_esc(cmdarg_T *cap) && cmdwin_type == 0 && !VIsual_active && no_reason) { - MSG(_("Type :qa! and press <Enter> to abandon all changes" - " and exit Nvim")); + if (anyBufIsChanged()) { + MSG(_("Type :qa! and press <Enter> to abandon all changes" + " and exit Nvim")); + } else { + MSG(_("Type :qa and press <Enter> to exit Nvim")); + } } /* Don't reset "restart_edit" when 'insertmode' is set, it won't be diff --git a/src/nvim/testdir/test_normal.vim b/src/nvim/testdir/test_normal.vim index ef17209f74..945cd5a617 100644 --- a/src/nvim/testdir/test_normal.vim +++ b/src/nvim/testdir/test_normal.vim @@ -2552,6 +2552,21 @@ func Test_delete_until_paragraph() bwipe! endfunc +func Test_message_when_using_ctrl_c() + " Make sure no buffers are changed. + %bwipe! + + exe "normal \<C-C>" + call assert_match("Type :qa and press <Enter> to exit Nvim", Screenline(&lines)) + + new + cal setline(1, 'hi!') + exe "normal \<C-C>" + call assert_match("Type :qa! and press <Enter> to abandon all changes and exit Nvim", Screenline(&lines)) + + bwipe! +endfunc + " Test for '[m', ']m', '[M' and ']M' " Jumping to beginning and end of methods in Java-like languages func Test_java_motion() diff --git a/src/nvim/undo.c b/src/nvim/undo.c index c9b0d96866..1305e013ad 100644 --- a/src/nvim/undo.c +++ b/src/nvim/undo.c @@ -2961,10 +2961,23 @@ static char_u *u_save_line(linenr_T lnum) /// /// @return true if the buffer has changed bool bufIsChanged(buf_T *buf) + FUNC_ATTR_WARN_UNUSED_RESULT { return !bt_dontwrite(buf) && (buf->b_changed || file_ff_differs(buf, true)); } +// Return true if any buffer has changes. Also buffers that are not written. +bool anyBufIsChanged(void) + FUNC_ATTR_WARN_UNUSED_RESULT +{ + FOR_ALL_BUFFERS(buf) { + if (bufIsChanged(buf)) { + return true; + } + } + return false; +} + /// Check if the 'modified' flag is set, or 'ff' has changed (only need to /// check the first character, because it can only be "dos", "unix" or "mac"). /// "nofile" and "scratch" type buffers are considered to always be unchanged. |