diff options
author | bptato <nincsnevem662@gmail.com> | 2025-03-25 23:11:46 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2025-03-25 23:53:12 +0100 |
commit | 76320b4a2b8677581ea45da644a7cc3a71544821 (patch) | |
tree | 46c892f45605eb505733ca0dc8010a7811c1e027 | |
parent | 6c56bff9a05d2ebf3bebd69131392f25941855ea (diff) | |
download | chawan-76320b4a2b8677581ea45da644a7cc3a71544821.tar.gz |
render: fix formatting generated for padding
The old logic was badly copy pasted from the pass that did text formatting; accordingly, it was overly complex and did not work correctly. Now we just add a single formatting cell to override the last one if it exists. (Formatting cells go from x position -> next cell or line end, and padding implies that the line had ended before the starting position of our text.) I've left in a workaround to what I think is a bug. It may be related to cursorNextLink getting stuck at the line's end...
-rw-r--r-- | src/css/render.nim | 44 |
1 files changed, 15 insertions, 29 deletions
diff --git a/src/css/render.nim b/src/css/render.nim index 3065a5d6..df679c91 100644 --- a/src/css/render.nim +++ b/src/css/render.nim @@ -127,36 +127,22 @@ proc setTextStr(line: var FlexibleLine; s, ostr: openArray[char]; proc setTextFormat(line: var FlexibleLine; x, cx, targetX: int; hadStr: bool; format: Format; node: Element) = var fi = line.findFormatN(cx) - 1 # Skip unchanged formats before new string - if x > cx: - # Replace formats for padding - var padformat = Format() - if fi == -1: - # No formats - inc fi # insert after first format (meaning fi = 0) - line.insertFormat(cx, fi, padformat) - else: + if x > cx and fi != -1: + # Amend formatting for padding. + # Since we only generate padding in place of non-existent text, it + # should be enough to just append a single format cell to erase the + # last one's effect. + # (This means that if fi is -1, we have nothing to erase -> nothing + # to do.) + if line.formats[fi].pos == cx: # First format's pos may be == cx here. - if line.formats[fi].pos == cx: - padformat.bgcolor = line.formats[fi].format.bgcolor - let node = line.formats[fi].node - line.formats[fi] = FormatCell(format: padformat, node: node, pos: cx) - else: - # First format < cx => split it up - assert line.formats[fi].pos < cx - padformat.bgcolor = line.formats[fi].format.bgcolor - let node = line.formats[fi].node - inc fi # insert after first format - line.insertFormat(cx, fi, padformat, node) - inc fi # skip last format - while fi < line.formats.len and line.formats[fi].pos <= x: - # Other formats must be > cx => replace them - padformat.bgcolor = line.formats[fi].format.bgcolor - let node = line.formats[fi].node - let px = line.formats[fi].pos - line.formats[fi] = FormatCell(format: padformat, node: node, pos: px) - inc fi - dec fi # go back to previous format, so that pos <= x - assert line.formats[fi].pos <= x + #TODO I'm not quite sure why. Isn't this a bug? + line.formats[fi] = FormatCell(format: Format(), pos: cx) + else: + # First format < cx => split it up + assert line.formats[fi].pos < cx + inc fi # insert after first format + line.insertFormat(cx, fi, Format()) # Now for the text's formats: var format = format var lformat: Format |