diff options
author | bptato <nincsnevem662@gmail.com> | 2022-12-27 21:36:35 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2022-12-27 22:34:10 +0100 |
commit | 65b0b48f445b6c56016a3c842089ef117a9298bc (patch) | |
tree | 3b82319e3ec57c24e2c191d83ecb755275d30933 /src/layout | |
parent | 4042ec0dd0515ac9d538e763d6b99b256b640eca (diff) | |
download | chawan-65b0b48f445b6c56016a3c842089ef117a9298bc.tar.gz |
Proper support for tabs
Diffstat (limited to 'src/layout')
-rw-r--r-- | src/layout/box.nim | 1 | ||||
-rw-r--r-- | src/layout/engine.nim | 13 |
2 files changed, 10 insertions, 4 deletions
diff --git a/src/layout/box.nim b/src/layout/box.nim index 9ce95fb8..a436cfae 100644 --- a/src/layout/box.nim +++ b/src/layout/box.nim @@ -93,6 +93,7 @@ type height*: int lines*: seq[LineBox] currentLine*: LineBox + charwidth*: int whitespacenum*: int minwidth*: int diff --git a/src/layout/engine.nim b/src/layout/engine.nim index c5536517..b26e0ebe 100644 --- a/src/layout/engine.nim +++ b/src/layout/engine.nim @@ -212,6 +212,7 @@ proc flushWhitespace(ictx: InlineContext, computed: CSSComputedValues) = proc finishLine(ictx: InlineContext, computed: CSSComputedValues, maxwidth: int, force = false) = if ictx.currentLine.atoms.len != 0 or force: ictx.whitespacenum = 0 + ictx.charwidth = 0 ictx.flushWhitespace(computed) ictx.verticalAlignLine() @@ -255,6 +256,7 @@ proc addAtom(ictx: InlineContext, atom: InlineAtom, maxwidth: int, pcomputed: CS if atom of InlineWord: ictx.format = InlineWord(atom).format else: + ictx.charwidth = 0 ictx.format = nil ictx.currentLine.atoms.add(atom) @@ -315,13 +317,14 @@ proc checkWrap(state: var InlineState, r: Rune) = proc processWhitespace(state: var InlineState, c: char) = state.addWord() case state.computed{"white-space"} - of WHITESPACE_NORMAL, WHITESPACE_NOWRAP: + of WHITESPACE_NORMAL, WHITESPACE_NOWRAP, WHITESPACE_PRE_LINE: state.ictx.whitespacenum = max(state.ictx.whitespacenum, 1) - of WHITESPACE_PRE_LINE, WHITESPACE_PRE, WHITESPACE_PRE_WRAP: + of WHITESPACE_PRE, WHITESPACE_PRE_WRAP: if c == '\n': state.ictx.flushLine(state.computed, state.maxwidth) elif c == '\t': - state.ictx.whitespacenum = (state.ictx.whitespacenum div 8 + 1) * 8 + state.ictx.charwidth = ((state.ictx.charwidth div 8) + 1) * 8 + state.word.str &= c else: inc state.ictx.whitespacenum @@ -348,7 +351,9 @@ proc renderText*(ictx: InlineContext, str: string, maxwidth: int, computed: CSSC state.hasshy = true else: state.word.str &= r - state.word.width += r.width() * state.ictx.cellwidth + let w = r.width() + state.word.width += w * state.ictx.cellwidth + state.ictx.charwidth += w if r == Rune('-'): # ascii dash state.wrappos = state.word.str.len state.hasshy = false |