From dbe0e29d85e2769be6c9738c176ba6d8b0c6817a Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Fri, 5 May 2023 14:06:59 +0200 Subject: [PATCH] fix(ui): don' render extmarks for empty lines --- lua/lazy/view/text.lua | 46 ++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/lua/lazy/view/text.lua b/lua/lazy/view/text.lua index edbf622b..614381a0 100644 --- a/lua/lazy/view/text.lua +++ b/lua/lazy/view/text.lua @@ -82,30 +82,32 @@ function Text:render(buf) vim.api.nvim_buf_clear_namespace(buf, Config.ns, 0, -1) for l, line in ipairs(self._lines) do - local col = self.padding - - for _, segment in ipairs(line) do - local width = vim.fn.strlen(segment.str) - - local extmark = segment.hl - if extmark and width > 0 then - if type(extmark) == "string" then - extmark = { hl_group = extmark, end_col = col + width } + if lines[l] ~= "" then + local col = self.padding + + for _, segment in ipairs(line) do + local width = vim.fn.strlen(segment.str) + + local extmark = segment.hl + if extmark then + if type(extmark) == "string" then + extmark = { hl_group = extmark, end_col = col + width } + end + ---@cast extmark Extmark + + local extmark_col = extmark.col or col + extmark.col = nil + local ok = pcall(vim.api.nvim_buf_set_extmark, buf, Config.ns, l - 1, extmark_col, extmark) + if not ok then + Util.error( + "Failed to set extmark. Please report a bug with this info:\n" + .. vim.inspect({ segment = segment, line = line }) + ) + end end - ---@cast extmark Extmark - - local extmark_col = extmark.col or col - extmark.col = nil - local ok = pcall(vim.api.nvim_buf_set_extmark, buf, Config.ns, l - 1, extmark_col, extmark) - if not ok then - Util.error( - "Failed to set extmark. Please report a bug with this info:\n" - .. vim.inspect({ segment = segment, line = line }) - ) - end - end - col = col + width + col = col + width + end end end end