aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/buffer/cell.nim21
-rw-r--r--src/render/renderdocument.nim27
2 files changed, 21 insertions, 27 deletions
diff --git a/src/buffer/cell.nim b/src/buffer/cell.nim
index a5e33645..3d1d32fa 100644
--- a/src/buffer/cell.nim
+++ b/src/buffer/cell.nim
@@ -4,7 +4,6 @@ import strutils
import sugar
import css/stylednode
-import layout/box
import types/color
import utils/twtstr
@@ -28,7 +27,6 @@ type
FormatCell* = object
format*: Format
pos*: int
- computed*: ComputedFormat
node*: StyledNode
SimpleFormatCell* = object
@@ -143,22 +141,11 @@ func findNextFormat*(line: SimpleFlexibleLine, pos: int): SimpleFormatCell =
proc addLine*(grid: var FlexibleGrid) =
grid.add(FlexibleLine())
-proc insertFormat*(line: var FlexibleLine, pos, i: int, format: Format, computed: ComputedFormat = nil) =
- if computed == nil:
- line.formats.insert(FormatCell(format: format, pos: pos), i)
- else:
- line.formats.insert(FormatCell(format: format, computed: computed, node: computed.node, pos: pos), i)
-
-proc addFormat*(line: var FlexibleLine, pos: int, format: Format) =
- line.formats.add(FormatCell(format: format, pos: pos))
+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 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))
+proc addFormat*(line: var FlexibleLine, pos: int, format: Format, node: StyledNode = nil) =
+ line.formats.add(FormatCell(format: format, node: node, pos: pos))
template inc_check(i: int) =
inc i
diff --git a/src/render/renderdocument.nim b/src/render/renderdocument.nim
index fd4be8da..5c9991a3 100644
--- a/src/render/renderdocument.nim
+++ b/src/render/renderdocument.nim
@@ -80,21 +80,24 @@ proc setText(lines: var FlexibleGrid, linestr: string, cformat: ComputedFormat,
# First format's pos may be == cx here.
if lines[y].formats[fi].pos == cx:
padformat.bgcolor = lines[y].formats[fi].format.bgcolor
+ let node = lines[y].formats[fi].node
lines[y].formats.delete(fi)
- lines[y].insertFormat(cx, fi, padformat)
+ lines[y].insertFormat(cx, fi, padformat, node)
else:
# First format < cx => split it up
assert lines[y].formats[fi].pos < cx
padformat.bgcolor = lines[y].formats[fi].format.bgcolor
+ let node = lines[y].formats[fi].node
inc fi # insert after first format
- lines[y].insertFormat(cx, fi, padformat)
+ lines[y].insertFormat(cx, fi, padformat, node)
inc fi # skip last format
while fi < lines[y].formats.len and lines[y].formats[fi].pos < x:
# Other formats must be > cx => replace them
padformat.bgcolor = lines[y].formats[fi].format.bgcolor
+ let node = lines[y].formats[fi].node
let px = lines[y].formats[fi].pos
lines[y].formats.delete(fi)
- lines[y].insertFormat(px, fi, padformat)
+ lines[y].insertFormat(px, fi, padformat, node)
inc fi
dec fi # go back to previous format, so that pos <= x
assert lines[y].formats[fi].pos <= x
@@ -102,25 +105,27 @@ proc setText(lines: var FlexibleGrid, linestr: string, cformat: ComputedFormat,
# Now for the text's formats:
var format = cformat.formatFromWord()
var lformat: Format
+ var lnode: StyledNode
if fi == -1:
# No formats => just insert a new format at 0
inc fi
- lines[y].insertFormat(x, fi, format, cformat)
+ lines[y].insertFormat(x, fi, format, cformat.node)
lformat = newFormat()
else:
# First format's pos may be == x here.
lformat = lines[y].formats[fi].format # save for later use
+ lnode = lines[y].formats[fi].node
if lines[y].formats[fi].pos == x:
# Replace.
format.bgcolor = lines[y].formats[fi].format.bgcolor
lines[y].formats.delete(fi)
- lines[y].insertFormat(x, fi, format, cformat)
+ lines[y].insertFormat(x, fi, format, cformat.node)
else:
# First format's pos < x => split it up.
assert lines[y].formats[fi].pos < x
format.bgcolor = lines[y].formats[fi].format.bgcolor
inc fi # insert after first format
- lines[y].insertFormat(x, fi, format, cformat)
+ lines[y].insertFormat(x, fi, format, cformat.node)
inc fi # skip last format
while fi < lines[y].formats.len and lines[y].formats[fi].pos < nx:
@@ -128,8 +133,9 @@ proc setText(lines: var FlexibleGrid, linestr: string, cformat: ComputedFormat,
format.bgcolor = lines[y].formats[fi].format.bgcolor
let px = lines[y].formats[fi].pos
lformat = lines[y].formats[fi].format # save for later use
+ lnode = lines[y].formats[fi].node
lines[y].formats.delete(fi)
- lines[y].insertFormat(px, fi, format, cformat)
+ lines[y].insertFormat(px, fi, format, cformat.node)
inc fi
if i < ostr.len and (fi >= lines[y].formats.len or lines[y].formats[fi].pos > nx):
@@ -137,7 +143,7 @@ proc setText(lines: var FlexibleGrid, linestr: string, cformat: ComputedFormat,
# string, and no formatting comes directly after it. So we insert the
# continuation of the last format we replaced after our string.
# (Default format when we haven't replaced anything.)
- lines[y].insertFormat(nx, fi, lformat)
+ lines[y].insertFormat(nx, fi, lformat, lnode)
dec fi # go back to previous format, so that pos <= nx
assert lines[y].formats[fi].pos <= nx
@@ -175,7 +181,7 @@ proc setSpacing(lines: var FlexibleGrid, spacing: InlineSpacing, x, y: int, wind
lines.setText(linestr, spacing.format, x, y)
-proc paintBackground(lines: var FlexibleGrid, color: RGBAColor, startx, starty, endx, endy: int, window: WindowAttributes) =
+proc paintBackground(lines: var FlexibleGrid, color: RGBAColor, startx, starty, endx, endy: int, node: StyledNode, window: WindowAttributes) =
let color = color.cellColor()
var starty = starty div window.ppl
@@ -251,6 +257,7 @@ proc paintBackground(lines: var FlexibleGrid, color: RGBAColor, startx, starty,
break
if lines[y].formats[fi].pos >= startx:
lines[y].formats[fi].format.bgcolor = color
+ lines[y].formats[fi].node = node
func calculateErrorY(ctx: InlineContext, window: WindowAttributes): int =
if ctx.lines.len <= 1: return 0
@@ -299,7 +306,7 @@ proc renderBlockContext(grid: var FlexibleGrid, ctx: BlockBox, x, y: int, window
y += ctx.offset.y
if ctx.computed{"background-color"}.a != 0: #TODO color blending
- grid.paintBackground(ctx.computed{"background-color"}, x, y, x + ctx.width, y + ctx.height, window)
+ grid.paintBackground(ctx.computed{"background-color"}, x, y, x + ctx.width, y + ctx.height, ctx.node, window)
if ctx.computed{"background-image"}.t == CONTENT_IMAGE:
# ugly hack for background-image display... TODO actually implement images
let s = ctx.computed{"background-image"}.s # [img]