aboutsummaryrefslogtreecommitdiffstats
path: root/src/types
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-11-20 15:45:25 +0100
committerbptato <nincsnevem662@gmail.com>2023-11-20 15:47:31 +0100
commitd20fc30e10aeecfb2ede7adc4547b9ae394565b9 (patch)
treec3cb2cbc2172edfc5835215d3af701b22bcb9e9c /src/types
parentdbb60a3cb0c1ada39692426e1b5a45245b3b791d (diff)
downloadchawan-d20fc30e10aeecfb2ede7adc4547b9ae394565b9.tar.gz
renderdocument, cell: fix FormatCell bugs
* No more zero width FormatCells messing up buffer display (yay!) * Assert on setText width a zero-length string * Remove unnecessary FormatCell added to every line on paintBackground start
Diffstat (limited to 'src/types')
-rw-r--r--src/types/cell.nim15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/types/cell.nim b/src/types/cell.nim
index 19a566cc..3a8967ee 100644
--- a/src/types/cell.nim
+++ b/src/types/cell.nim
@@ -31,6 +31,10 @@ type
format*: Format
pos*: int
+ # Following properties should hold for `formats':
+ # * Position should be >= 0, <= str.width().
+ # * The position of every FormatCell should be greater than the position
+ # of the previous FormatCell.
FlexibleLine* = object
str*: string
formats*: seq[FormatCell]
@@ -146,10 +150,15 @@ proc addLine*(grid: var FlexibleGrid) =
proc addLines*(grid: var FlexibleGrid, n: int) =
grid.setLen(grid.len + n)
-proc insertFormat*(line: var FlexibleLine, pos, i: int, format: Format, node: StyledNode = nil) =
- line.formats.insert(FormatCell(format: format, node: node, pos: pos), i)
+proc insertFormat*(line: var FlexibleLine, i: int, cell: FormatCell) =
+ line.formats.insert(cell, i)
-proc addFormat*(line: var FlexibleLine, pos: int, format: Format, node: StyledNode = nil) =
+proc insertFormat*(line: var FlexibleLine, pos, i: int, format: Format,
+ node: StyledNode = nil) =
+ line.insertFormat(i, FormatCell(format: format, node: node, pos: pos))
+
+proc addFormat*(line: var FlexibleLine, pos: int, format: Format,
+ node: StyledNode = nil) =
line.formats.add(FormatCell(format: format, node: node, pos: pos))
# https://www.ecma-international.org/wp-content/uploads/ECMA-48_5th_edition_june_1991.pdf