This commit is contained in:
Robert Jelic
2023-06-15 18:22:45 +02:00

View File

@@ -167,34 +167,42 @@ local function wrapRichText(text, width)
elseif entry.bgColor then elseif entry.bgColor then
currentBgColor = entry.bgColor currentBgColor = entry.bgColor
else else
local words = splitString(entry.text, " ") local paragraphs = splitString(entry.text, "\n")
for p, paragraph in ipairs(paragraphs) do
local words = splitString(paragraph, " ")
for i, word in ipairs(words) do for i, word in ipairs(words) do
local wordLength = #word local wordLength = #word
if i > 1 then if i > 1 then
if x + 1 + wordLength <= width then if x + 1 + wordLength <= width then
addFormattedEntry({ text = " " }) addFormattedEntry({ text = " " })
x = x + 1 x = x + 1
else else
x = 1 x = 1
y = y + 1 y = y + 1
end
end
while wordLength > 0 do
local line = word:sub(1, width - x + 1)
word = word:sub(width - x + 2)
wordLength = #word
addFormattedEntry({ text = line })
if wordLength > 0 then
x = 1
y = y + 1
else
x = x + #line
end
end end
end end
while wordLength > 0 do if p ~= #paragraphs then
local line = word:sub(1, width - x + 1) x = 1
word = word:sub(width - x + 2) y = y + 1
wordLength = #word
addFormattedEntry({ text = line })
if wordLength > 0 then
x = 1
y = y + 1
else
x = x + #line
end
end end
end end
end end
@@ -209,6 +217,7 @@ local function wrapRichText(text, width)
end end
return { return {
@@ -340,4 +349,4 @@ uuid = function()
return string.gsub(string.format('%x-%x-%x-%x-%x', math.random(0, 0xffff), math.random(0, 0xffff), math.random(0, 0xffff), math.random(0, 0x0fff) + 0x4000, math.random(0, 0x3fff) + 0x8000), ' ', '0') return string.gsub(string.format('%x-%x-%x-%x-%x', math.random(0, 0xffff), math.random(0, 0xffff), math.random(0, 0xffff), math.random(0, 0x0fff) + 0x4000, math.random(0, 0x3fff) + 0x8000), ' ', '0')
end end
} }