From f93f67cdd0f34409f88b1507252055ca4c5fb9bc Mon Sep 17 00:00:00 2001 From: bptato Date: Wed, 19 Jan 2022 21:09:21 +0100 Subject: Fix whitespace issues after newline --- src/layout/engine.nim | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'src/layout') diff --git a/src/layout/engine.nim b/src/layout/engine.nim index f74c5f6c..afd66c72 100644 --- a/src/layout/engine.nim +++ b/src/layout/engine.nim @@ -525,24 +525,22 @@ proc finishRow(ictx: InlineContext) = proc addAtom(ictx: InlineContext, atom: InlineAtom, maxwidth: int, specified: CSSSpecifiedValues) = # Whitespace between words + var shift = 0 + let whitespacepre = specified{"white-space"} in {WHITESPACE_PRE, WHITESPACE_PRE_WRAP} if ictx.whitespace: - if ictx.thisrow.atoms.len > 0: - inc ictx.thisrow.width - ictx.whitespace = false - elif specified{"white-space"} in {WHITESPACE_PRE, WHITESPACE_PRE_WRAP}: - inc ictx.thisrow.width - else: - ictx.whitespace = false + if ictx.thisrow.atoms.len > 0 or whitespacepre: + shift = 1 + ictx.whitespace = false # Line wrapping if specified{"white-space"} notin {WHITESPACE_NOWRAP, WHITESPACE_PRE}: if specified{"word-break"} == WORD_BREAK_NORMAL and ictx.thisrow.width + atom.width > maxwidth: ictx.finishRow() + if not whitespacepre: + # No whitespace on newline + shift = 0 - # Whitespace (from pre/pre-wrap) - if ictx.whitespace: - inc ictx.thisrow.relx - ictx.whitespace = false + ictx.thisrow.width += shift atom.relx = ictx.thisrow.width ictx.thisrow.width += atom.width -- cgit 1.4.1-2-gfad0