Skip to content

Commit 00a6f38

Browse files
committed
fix(messages): Fixed a bug with certain messagses duplicating on redraw
This still needs to be fixed in `neovim/neovim`.
1 parent 6f893e4 commit 00a6f38

1 file changed

Lines changed: 14 additions & 14 deletions

File tree

lua/ui/message.lua

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -247,23 +247,23 @@ end
247247
message.__add = function (kind, content, add_to_history)
248248
---|fS
249249

250-
if kind == "" and vim.tbl_isempty(message.visible) == false then
251-
---@type integer[] Message IDs.
252-
local IDs = vim.tbl_keys(message.visible);
253-
table.sort(IDs);
250+
if kind == "" and vim.tbl_isempty(message.history) == false then
251+
-- Calling `nvim__redraw()` causes messages to duplicate
252+
-- with incorrect kind.
253+
-- So, we check if that's the case and handle accordingly.
254254

255-
--- Last visible message.
256-
local last = message.visible[IDs[#IDs]];
255+
--- Last shown message.
256+
local last_shown = message.history[message.id - 1];
257257

258-
if vim.deep_equal(last.content, content) then
259-
-- BUG, Vim resends old message on redraw.
260-
-- Last message will be replaced with this
261-
-- one.
262-
--
263-
-- The second message has the wrong kind so
264-
-- we use the original kind.
258+
--- Last visible message.
259+
local last_visible = message.visible[message.id - 1];
265260

266-
message.__replace(last.kind, content, false);
261+
if last_visible and vim.deep_equal(last_visible.content, content) then
262+
-- Message is still visible, extend duration.
263+
message.__replace(last_visible.kind, content, false);
264+
return;
265+
elseif last_shown and vim.deep_equal(last_shown.content, content) then
266+
-- Message is not visible, discard this one.
267267
return;
268268
end
269269
end

0 commit comments

Comments
 (0)