about summary refs log tree commit diff stats
path: root/src/layout
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-02-27 22:05:01 +0100
committerbptato <nincsnevem662@gmail.com>2024-02-27 22:24:26 +0100
commitc61db0e0d69c8df4cd2309ce8b9a40b5a82a84d9 (patch)
tree009a4b4f84188acccf9959030a4d8a373ee31e4e /src/layout
parent869c65a02e04db05e83f21cc77fe45e4f8e95513 (diff)
downloadchawan-c61db0e0d69c8df4cd2309ce8b9a40b5a82a84d9.tar.gz
Fix tab size bug on double tabs
It is in fact quite simple to calculate: charwidth is the width
of printing characters until now, and whitespacenum the number of
(non-flushed) spaces. So we just have to subtract this from the target
width to get the number of spaces missing from the next tab stop.

(Of course, it gets much harder to understand when the whole thing is
formatted as a convoluted multi-line equation...)
Diffstat (limited to 'src/layout')
-rw-r--r--src/layout/engine.nim8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/layout/engine.nim b/src/layout/engine.nim
index 93a324b3..0377dbb0 100644
--- a/src/layout/engine.nim
+++ b/src/layout/engine.nim
@@ -677,10 +677,10 @@ proc processWhitespace(ictx: var InlineContext, state: var InlineState,
     if c == '\n':
       ictx.flushLine(state)
     elif c == '\t':
-      let prev = ictx.currentLine.charwidth
-      ictx.currentLine.charwidth = ((ictx.currentLine.charwidth +
-        ictx.whitespacenum) div 8 + 1) * 8 - ictx.whitespacenum
-      ictx.whitespacenum += ictx.currentLine.charwidth - prev
+      let realWidth = ictx.currentLine.charwidth + ictx.whitespacenum
+      let targetTabStops = realWidth div 8 + 1
+      let targetWidth = targetTabStops * 8
+      ictx.whitespacenum += targetWidth - realWidth
       ictx.whitespaceFragment = state.fragment
     else:
       inc ictx.whitespacenum