about summary refs log tree commit diff stats
path: root/src/layout
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-02-14 15:55:23 +0100
committerbptato <nincsnevem662@gmail.com>2023-02-14 15:55:23 +0100
commit89b63627036cb93737e84beac7ab9c516daf2fb0 (patch)
treea64ea4257660b1e90e5a87874fe6b32ea3552515 /src/layout
parente230b24c3673e09258b4b9ad732a097e5df970cc (diff)
downloadchawan-89b63627036cb93737e84beac7ab9c516daf2fb0.tar.gz
layout/engine: fix some tab alignment issues
Diffstat (limited to 'src/layout')
-rw-r--r--src/layout/engine.nim6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/layout/engine.nim b/src/layout/engine.nim
index 37edd21b..eebc7ef0 100644
--- a/src/layout/engine.nim
+++ b/src/layout/engine.nim
@@ -212,13 +212,13 @@ proc addSpacing(line: LineBox, width, height: int, format: ComputedFormat, hang
 
 proc flushWhitespace(ictx: InlineContext, computed: CSSComputedValues, hang = false) =
   let shift = ictx.computeShift(computed)
+  ictx.charwidth += ictx.whitespacenum
   ictx.whitespacenum = 0
   if shift > 0:
     ictx.currentLine.addSpacing(shift, ictx.cellheight, ictx.format, hang)
 
 proc finishLine(ictx: InlineContext, computed: CSSComputedValues, force = false) =
   if ictx.currentLine.atoms.len != 0 or force:
-    ictx.charwidth = 0
     let whitespace = computed{"white-space"}
     if whitespace == WHITESPACE_PRE:
       ictx.flushWhitespace(computed)
@@ -233,6 +233,7 @@ proc finishLine(ictx: InlineContext, computed: CSSComputedValues, force = false)
     ictx.height += line.height
     ictx.width = max(ictx.width, line.width)
     ictx.currentLine = LineBox(offset: Offset(y: line.offset.y + line.height))
+    ictx.charwidth = 0
 
 proc finish(ictx: InlineContext, computed: CSSComputedValues) =
   ictx.finishLine(computed)
@@ -343,7 +344,8 @@ proc processWhitespace(state: var InlineState, c: char) =
       state.ictx.flushLine(state.computed)
     elif c == '\t':
       let prev = state.ictx.charwidth
-      state.ictx.charwidth = ((state.ictx.charwidth div 8) + 1) * 8
+      state.ictx.charwidth = ((state.ictx.charwidth +
+        state.ictx.whitespacenum div 8) + 1) * 8 - state.ictx.whitespacenum
       state.ictx.whitespacenum += state.ictx.charwidth - prev
     else:
       inc state.ictx.whitespacenum