Skip to content

Commit

Permalink
fix: properly handle carriage returns. Fixes #190
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Nov 13, 2022
1 parent 5ff75a5 commit c14b064
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lua/noice/text/block.lua
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ function Block:append(contents, highlight)
-- Handle newlines
---@type number|string|table, string
local attr_id, text = unpack(content)
text = text:gsub("\r", "")
text = text:gsub("\r\n", "\n")

---@type string|table|nil
local hl_group
if type(attr_id) == "number" then
Expand All @@ -169,6 +170,16 @@ 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

0 comments on commit c14b064

Please sign in to comment.