about summary refs log tree commit diff stats
path: root/src/io/cell.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2022-02-19 12:38:15 +0100
committerbptato <nincsnevem662@gmail.com>2022-02-19 12:44:01 +0100
commit7d80da8a8e40c591d0dbceb4d0c79ca6dab16917 (patch)
tree03999396581ac4b0a2d23882b9241448fb92ce2d /src/io/cell.nim
parent1aec6113a6dbae0878f849675ec9d1417cb6a787 (diff)
downloadchawan-7d80da8a8e40c591d0dbceb4d0c79ca6dab16917.tar.gz
Reduce formatting complexity
Formatting based on cells instead of bytes. No clue why I'd ever thought
the latter would be a good idea.
This fixes background colors too. I think.
Diffstat (limited to 'src/io/cell.nim')
-rw-r--r--src/io/cell.nim10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/io/cell.nim b/src/io/cell.nim
index af142967..abcb8f92 100644
--- a/src/io/cell.nim
+++ b/src/io/cell.nim
@@ -142,9 +142,13 @@ proc addLine*(grid: var FlexibleGrid) =
 proc addFormat*(line: var FlexibleLine, pos: int, format: Format) =
   line.formats.add(FormatCell(format: format, pos: line.str.len))
 
-proc addFormat*(grid: var FlexibleGrid, y, pos: int, format: Format, computed: ComputedFormat = nil, node: Node = nil) =
-  if computed == nil or grid[y].formats.len == 0 or grid[y].formats[^1].computed != computed:
-    grid[y].formats.add(FormatCell(format: format, node: node, computed: computed, pos: pos))
+proc addFormat*(line: var FlexibleLine, pos: int, format: Format, computed: ComputedFormat) =
+  if computed != nil and line.formats.len > 0 and line.formats[^1].computed == computed and line.formats[^1].format.bgcolor != format.bgcolor:
+    return
+  if computed == nil:
+    line.formats.add(FormatCell(format: format, pos: pos))
+  else:
+    line.formats.add(FormatCell(format: format, computed: computed, node: computed.node, pos: pos))
 
 template inc_check(i: int) =
   inc i