Skip to content

Commit

Permalink
fix(text): better (correct) way of dealing with \r characters. Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed May 27, 2023
1 parent 1478f72 commit 520a737
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions lua/noice/text/block.lua
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ function Block:_append(content, highlight)
if #self._lines == 0 then
table.insert(self._lines, NuiLine())
end
if type(content) == "string" then
-- handle carriage returns. They overwrite the line from the first character
local cr = content:match("^.*()[\r^M]")
if cr then
table.remove(self._lines)
table.insert(self._lines, NuiLine())
content = content:sub(cr + 1)
end
end
return self._lines[#self._lines]:append(content, highlight)
end

Expand Down Expand Up @@ -156,7 +165,6 @@ function Block:append(contents, highlight)
-- Handle newlines
---@type number|string|table, string
local attr_id, text = unpack(content)
text = text:gsub("\r\n", "\n")

---@type string|table|nil
local hl_group
Expand All @@ -170,16 +178,6 @@ function Block:append(contents, highlight)
local nl = text:find("\n")
if nl then
local str = text:sub(1, nl - 1)

-- handle carriage returns. They overwrite the line from the first character
if str:find("\r") then
local parts = vim.split(str, "\r", { plain = true })
str = ""
for _, p in ipairs(parts) do
str = p .. str:sub(p:len() + 1)
end
end

self:_append(str, hl_group)
self:newline()
text = text:sub(nl + 1)
Expand Down

3 comments on commit 520a737

@paulo-santana
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somehow this change broke the documentation window when using clangd as LSP. I tested with rust-analyzer and it seems to be still working fine. I'll open an issue about it, but it will take me some time if I were going to fix it

@folke
Copy link
Owner Author

@folke folke commented on 520a737 May 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@paulo-santana I know what's causing this. My bad. I pushed a temporary fix, that should at least show data again.

Will properly fix it later tonight. Have to go now.

Would still be good if you can confirm it works for you again now.

Thanks

@paulo-santana
Copy link

@paulo-santana paulo-santana commented on 520a737 May 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did some testing, the issue still happens. The Hover (K) window was being shown, it was just the highlighting that was broken. The doc window that appears aside the nvim-cmp completion options is still broken.

Please sign in to comment.