From 21718c67dd9625c53d519a63725db55be6abe2ff Mon Sep 17 00:00:00 2001 From: luukvbaal Date: Fri, 3 Jan 2025 17:25:06 +0100 Subject: [PATCH] fix(messages): better formatting for ext_messages #31839 Problem: Message grid newline formatting based on `msg_col` is not utilized with ext_messages. Solution: Increment `msg_col` with the cell width of the chunk. Allowing message code that uses `msg_col` to determine when to place a newline to do so. E.g. when the message goes beyond `Columns`; this is not necessarily where the ext_messages implementation would want to place a newline, but it is a best guess. Message parsing and manipulation is still possible. --- src/nvim/digraph.c | 1 + src/nvim/message.c | 1 + test/functional/ui/messages_spec.lua | 17 ++++++++++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/nvim/digraph.c b/src/nvim/digraph.c index 876d38ea83..aaa77f5fcf 100644 --- a/src/nvim/digraph.c +++ b/src/nvim/digraph.c @@ -1714,6 +1714,7 @@ void listdigraphs(bool use_headers) { result_T previous = 0; + msg_ext_set_kind("list_cmd"); msg_putchar('\n'); const digr_T *dp = digraphdefault; diff --git a/src/nvim/message.c b/src/nvim/message.c index 69e8f66bbe..661d0754d4 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -2222,6 +2222,7 @@ static void msg_puts_display(const char *str, int maxlen, int hl_id, int recurse size_t len = maxlen < 0 ? strlen(str) : strnlen(str, (size_t)maxlen); ga_concat_len(&msg_ext_last_chunk, str, len); msg_ext_cur_len += len; + msg_col += (int)mb_string2cells(str); // When message ends in newline, reset variables used to format message: msg_advance(). assert(len > 0); if (str[len - 1] == '\n') { diff --git a/test/functional/ui/messages_spec.lua b/test/functional/ui/messages_spec.lua index 1e51652c4f..77ffc475b0 100644 --- a/test/functional/ui/messages_spec.lua +++ b/test/functional/ui/messages_spec.lua @@ -1121,7 +1121,7 @@ stack traceback: ]], messages = { { - content = { { 'wildmenu wildmode' } }, + content = { { 'wildmenu wildmode\n' } }, history = false, kind = 'wildlist', }, @@ -1335,6 +1335,21 @@ stack traceback: feed('i') n.assert_alive() end) + + it(':digraph contains newlines', function() + command('digraph') + screen:expect({ + condition = function() + local nl = 0 + eq('list_cmd', screen.messages[1].kind) + for _, chunk in ipairs(screen.messages[1].content) do + nl = nl + (chunk[2]:find('\n') and 1 or 0) + end + eq(682, nl) + screen.messages = {} + end, + }) + end) end) describe('ui/builtin messages', function()