diff options
author | bptato <nincsnevem662@gmail.com> | 2022-11-29 22:31:21 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2022-11-29 22:31:21 +0100 |
commit | f2daba3542cabb4741e2dc38d1bf36a2d1564f60 (patch) | |
tree | 7cc676dc81312f8a97f3a0ecc7c6db30c61f56f8 /src/render | |
parent | 00b54f6fff8eb001950689650d595c2b23a3f639 (diff) | |
download | chawan-f2daba3542cabb4741e2dc38d1bf36a2d1564f60.tar.gz |
renderdocument: fix bug negative padwidth bug
padwidth could be negative because we didn't ensure cx <= x.
Diffstat (limited to 'src/render')
-rw-r--r-- | src/render/renderdocument.nim | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/render/renderdocument.nim b/src/render/renderdocument.nim index 52f4b0c4..f1b131ae 100644 --- a/src/render/renderdocument.nim +++ b/src/render/renderdocument.nim @@ -39,8 +39,15 @@ proc setText(lines: var FlexibleGrid, linestr: string, cformat: ComputedFormat, var cx = 0 # first x of new string (before padding) while cx < x and i < lines[y].str.len: + let pi = i fastRuneAt(lines[y].str, i, r) - cx += r.width() + let w = r.width() + # we must ensure x is max(cx, x), otherwise our assumption of cx <= x + # breaks down + if cx + w > x: + i = pi + break + cx += w let ostr = lines[y].str.substr(i) lines[y].str.setLen(i) |