aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjörn Linse <bjorn.linse@gmail.com>2019-06-16 12:34:27 +0200
committerGitHub <noreply@github.com>2019-06-16 12:34:27 +0200
commit3d6e48a941acab51d8c045ec325783c0107a5d54 (patch)
tree50a56b49db6e743f46f63047cbaf9d071c34ba25
parent5a96161e8664339c11a904b6f851f44d9c5b49d3 (diff)
parente39d217592d83566bba004dc80120f22f59b544b (diff)
downloadrneovim-3d6e48a941acab51d8c045ec325783c0107a5d54.tar.gz
rneovim-3d6e48a941acab51d8c045ec325783c0107a5d54.tar.bz2
rneovim-3d6e48a941acab51d8c045ec325783c0107a5d54.zip
Merge pull request #10150 from bfredl/extcount
make msg_advance and search_count not crash with ext_messages, fixes #10069
-rw-r--r--runtime/doc/ui.txt1
-rw-r--r--src/nvim/message.c21
-rw-r--r--src/nvim/search.c5
-rw-r--r--test/functional/ui/messages_spec.lua45
4 files changed, 68 insertions, 4 deletions
diff --git a/runtime/doc/ui.txt b/runtime/doc/ui.txt
index ca10edccba..c56f9467a3 100644
--- a/runtime/doc/ui.txt
+++ b/runtime/doc/ui.txt
@@ -706,6 +706,7 @@ events, which the UI must handle.
"rpc_error" Error response from |rpcrequest()|
"return_prompt" |press-enter| prompt after a multiple messages
"quickfix" Quickfix navigation message
+ "search_count" Search count message ("S" flag of 'shortmess')
"wmsg" Warning ("search hit BOTTOM", |W10|, …)
New kinds may be added in the future; clients should treat unknown
kinds as the empty kind.
diff --git a/src/nvim/message.c b/src/nvim/message.c
index 5188824901..86c185dbc2 100644
--- a/src/nvim/message.c
+++ b/src/nvim/message.c
@@ -116,6 +116,7 @@ static const char *msg_ext_kind = NULL;
static Array msg_ext_chunks = ARRAY_DICT_INIT;
static garray_T msg_ext_last_chunk = GA_INIT(sizeof(char), 40);
static sattr_T msg_ext_last_attr = -1;
+static size_t msg_ext_cur_len = 0;
static bool msg_ext_overwrite = false; ///< will overwrite last message
static int msg_ext_visible = 0; ///< number of messages currently visible
@@ -1877,8 +1878,9 @@ static void msg_puts_display(const char_u *str, int maxlen, int attr,
msg_ext_last_attr = attr;
}
// Concat pieces with the same highlight
- ga_concat_len(&msg_ext_last_chunk, (char *)str,
- strnlen((char *)str, maxlen)); // -V781
+ size_t len = strnlen((char *)str, maxlen);
+ ga_concat_len(&msg_ext_last_chunk, (char *)str, len); // -V781
+ msg_ext_cur_len += len;
return;
}
@@ -2770,6 +2772,7 @@ void msg_ext_ui_flush(void)
}
msg_ext_kind = NULL;
msg_ext_chunks = (Array)ARRAY_DICT_INIT;
+ msg_ext_cur_len = 0;
msg_ext_overwrite = false;
}
}
@@ -2782,6 +2785,7 @@ void msg_ext_flush_showmode(void)
msg_ext_emit_chunk();
ui_call_msg_showmode(msg_ext_chunks);
msg_ext_chunks = (Array)ARRAY_DICT_INIT;
+ msg_ext_cur_len = 0;
}
}
@@ -3018,7 +3022,10 @@ void give_warning(char_u *message, bool hl) FUNC_ATTR_NONNULL_ARG(1)
} else {
keep_msg_attr = 0;
}
- msg_ext_set_kind("wmsg");
+
+ if (msg_ext_kind == NULL) {
+ msg_ext_set_kind("wmsg");
+ }
if (msg_attr((const char *)message, keep_msg_attr) && msg_scrolled == 0) {
set_keep_msg(message, keep_msg_attr);
@@ -3045,6 +3052,14 @@ void msg_advance(int col)
msg_col = col; /* for redirection, may fill it up later */
return;
}
+ if (ui_has(kUIMessages)) {
+ // TODO(bfredl): use byte count as a basic proxy.
+ // later on we might add proper support for formatted messages.
+ while (msg_ext_cur_len < (size_t)col) {
+ msg_putchar(' ');
+ }
+ return;
+ }
if (col >= Columns) /* not enough room */
col = Columns - 1;
if (cmdmsg_rl)
diff --git a/src/nvim/search.c b/src/nvim/search.c
index 3834bf9700..9cbe21bdc8 100644
--- a/src/nvim/search.c
+++ b/src/nvim/search.c
@@ -1168,7 +1168,9 @@ int do_search(
// search stat. Use all the space available, so that the
// search state is right aligned. If there is not enough space
// msg_strtrunc() will shorten in the middle.
- if (msg_scrolled != 0) {
+ if (ui_has(kUIMessages)) {
+ len = 0; // adjusted below
+ } else if (msg_scrolled != 0) {
// Use all the columns.
len = (int)(Rows - msg_row) * Columns - 1;
} else {
@@ -4328,6 +4330,7 @@ static void search_stat(int dirc, pos_T *pos,
// keep the message even after redraw, but don't put in history
msg_hist_off = true;
+ msg_ext_set_kind("search_count");
give_warning(msgbuf, false);
msg_hist_off = false;
}
diff --git a/test/functional/ui/messages_spec.lua b/test/functional/ui/messages_spec.lua
index 7d21f40ce9..e6df9885ef 100644
--- a/test/functional/ui/messages_spec.lua
+++ b/test/functional/ui/messages_spec.lua
@@ -21,6 +21,8 @@ describe('ui/ext_messages', function()
[4] = {bold = true, foreground = Screen.colors.SeaGreen4},
[5] = {foreground = Screen.colors.Blue1},
[6] = {bold = true, reverse = true},
+ [7] = {background = Screen.colors.Yellow},
+ [8] = {foreground = Screen.colors.Red},
})
end)
after_each(function()
@@ -303,6 +305,49 @@ describe('ui/ext_messages', function()
}}
end)
+ it('shortmess-=S', function()
+ command('set shortmess-=S')
+ feed('iline 1\nline 2<esc>')
+
+ feed('/line<cr>')
+ screen:expect{grid=[[
+ {7:^line} 1 |
+ {7:line} 2 |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ]], messages={
+ {content = {{"/line [1/2] W"}}, kind = "search_count"}
+ }}
+
+ feed('n')
+ screen:expect{grid=[[
+ {7:line} 1 |
+ {7:^line} 2 |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ]], messages={
+ {content = {{"/line [2/2]"}}, kind = "search_count"}
+ }}
+ end)
+
+ it("doesn't crash with column adjustment #10069", function()
+ feed(':let [x,y] = [1,2]<cr>')
+ feed(':let x y<cr>')
+ screen:expect{grid=[[
+ ^ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ ]], messages={
+ {content = {{ "x #1" }}, kind = ""},
+ {content = {{ "y #2" }}, kind = ""},
+ {content = {{ "Press ENTER or type command to continue", 4 }}, kind = "return_prompt"}
+ }}
+ end)
+
it('&showmode', function()
command('imap <f2> <cmd>echomsg "stuff"<cr>')
feed('i')