diff options
-rw-r--r-- | src/nvim/message.c | 10 | ||||
-rw-r--r-- | src/nvim/testdir/test_messages.vim | 19 | ||||
-rw-r--r-- | test/functional/legacy/messages_spec.lua | 38 |
3 files changed, 65 insertions, 2 deletions
diff --git a/src/nvim/message.c b/src/nvim/message.c index b3fefbc0f4..7b90f882ab 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -1486,6 +1486,10 @@ int msg_outtrans_len_attr(const char_u *msgstr, int len, int attr) char_u *s; int mb_l; int c; + int save_got_int = got_int; + + // Only quit when got_int was set in here. + got_int = false; // if MSG_HIST flag set, add message to history if (attr & MSG_HIST) { @@ -1503,7 +1507,7 @@ int msg_outtrans_len_attr(const char_u *msgstr, int len, int attr) * Go over the string. Special characters are translated and printed. * Normal characters are printed several at a time. */ - while (--len >= 0) { + while (--len >= 0 && !got_int) { // Don't include composing chars after the end. mb_l = utfc_ptr2len_len((char_u *)str, len + 1); if (mb_l > 1) { @@ -1542,11 +1546,13 @@ int msg_outtrans_len_attr(const char_u *msgstr, int len, int attr) } } - if (str > plain_start) { + if (str > plain_start && !got_int) { // Print the printable chars at the end. msg_puts_attr_len(plain_start, str - plain_start, attr); } + got_int |= save_got_int; + return retval; } diff --git a/src/nvim/testdir/test_messages.vim b/src/nvim/testdir/test_messages.vim index 9c84d77dd2..65de0bb169 100644 --- a/src/nvim/testdir/test_messages.vim +++ b/src/nvim/testdir/test_messages.vim @@ -2,6 +2,9 @@ source check.vim source shared.vim +source term_util.vim +source view_util.vim +source screendump.vim func Test_messages() let oldmore = &more @@ -109,6 +112,22 @@ func Test_echospace() set ruler& showcmd& endfunc +func Test_quit_long_message() + CheckScreendump + + let content =<< trim END + echom range(9999)->join("\x01") + END + call writefile(content, 'Xtest_quit_message') + let buf = RunVimInTerminal('-S Xtest_quit_message', #{rows: 6}) + call term_sendkeys(buf, "q") + call VerifyScreenDump(buf, 'Test_quit_long_message', {}) + + " clean up + call StopVimInTerminal(buf) + call delete('Xtest_quit_message') +endfunc + " this was missing a terminating NUL func Test_echo_string_partial() function CountSpaces() diff --git a/test/functional/legacy/messages_spec.lua b/test/functional/legacy/messages_spec.lua new file mode 100644 index 0000000000..330d70e7d4 --- /dev/null +++ b/test/functional/legacy/messages_spec.lua @@ -0,0 +1,38 @@ +local helpers = require('test.functional.helpers')(after_each) +local Screen = require('test.functional.ui.screen') +local clear = helpers.clear +local command = helpers.command +local feed = helpers.feed + +before_each(clear) + +describe('messages', function() + it('more prompt with control characters can be quit vim-patch:8.2.1844', function() + local screen = Screen.new(40, 6) + screen:set_default_attr_ids({ + [1] = {foreground = Screen.colors.Blue}, -- SpecialKey + [2] = {bold = true, foreground = Screen.colors.SeaGreen}, -- MoreMsg + [3] = {bold = true, foreground = Screen.colors.Blue}, -- NonText + }) + screen:attach() + command('set more') + feed([[:echom range(9999)->join("\x01")<CR>]]) + screen:expect([[ + 0{1:^A}1{1:^A}2{1:^A}3{1:^A}4{1:^A}5{1:^A}6{1:^A}7{1:^A}8{1:^A}9{1:^A}10{1:^A}11{1:^A}12| + {1:^A}13{1:^A}14{1:^A}15{1:^A}16{1:^A}17{1:^A}18{1:^A}19{1:^A}20{1:^A}21{1:^A}22| + {1:^A}23{1:^A}24{1:^A}25{1:^A}26{1:^A}27{1:^A}28{1:^A}29{1:^A}30{1:^A}31{1:^A}32| + {1:^A}33{1:^A}34{1:^A}35{1:^A}36{1:^A}37{1:^A}38{1:^A}39{1:^A}40{1:^A}41{1:^A}42| + {1:^A}43{1:^A}44{1:^A}45{1:^A}46{1:^A}47{1:^A}48{1:^A}49{1:^A}50{1:^A}51{1:^A}52| + {2:-- More --}^ | + ]]) + feed('q') + screen:expect([[ + ^ | + {3:~ }| + {3:~ }| + {3:~ }| + {3:~ }| + | + ]]) + end) +end) |