Fixed a fix

Forgot i have to split by words and not just split when width has reached.
This commit is contained in:
Robert Jelic
2022-12-18 00:43:09 +01:00
committed by GitHub
parent 923b570d48
commit 2c4c059a70

View File

@@ -140,10 +140,19 @@ createText = function(str, width)
local result = {}
for k,v in pairs(uniqueLines)do
if(#v==0)then table.insert(result, "") end
local start = 1
while start <= #v do
table.insert(result, sub(v, start, start + width - 1))
start = start + width
while #v > width do
local last_space = find(reverse(sub(v, 1, width)), " ")
if not last_space then
last_space = width
else
last_space = width - last_space + 1
end
local line = sub(v, 1, last_space)
table.insert(result, line)
v = sub(v, last_space + 1)
end
if #v > 0 then
table.insert(result, v)
end
end
return result