Check indent and justify after lines are combined in tokenizer, not before (#2426)

This commit is contained in:
Veronica Berglyd Olsen
2025-06-23 23:24:20 +02:00
parent 0bbe29bc2e
commit 3c474987b2
3 changed files with 93 additions and 17 deletions
+74
View File
@@ -1074,6 +1074,80 @@ def testFmtToken_Paragraphs(mockGUI):
]
@pytest.mark.core
def testFmtToken_BreakAlignIndent(mockGUI):
"""Test the splitting of paragraphs with alignment."""
project = NWProject()
tokens = BareTokenizer(project)
tokens._handle = TMH
for text in [
"This is text <<\nspanning multiple\nlines",
"This is text\nspanning multiple <<\nlines",
"This is text\nspanning multiple\nlines <<",
]:
# Preserve Breaks
tokens.setKeepLineBreaks(True)
tokens._text = text
tokens.tokenizeText()
assert tokens._blocks == [
(BlockTyp.TEXT, "", "This is text\nspanning multiple\nlines", [], BlockFmt.LEFT),
]
# Don't Preserve Breaks
tokens.setKeepLineBreaks(False)
tokens._text = text
tokens.tokenizeText()
assert tokens._blocks == [
(BlockTyp.TEXT, "", "This is text spanning multiple lines", [], BlockFmt.LEFT),
]
# With Justify
# This should disable justify
tokens.setKeepLineBreaks(True)
tokens.setJustify(True)
tokens._text = text
tokens.tokenizeText()
assert tokens._blocks == [
(BlockTyp.TEXT, "", "This is text\nspanning multiple\nlines", [], BlockFmt.LEFT),
]
# With Indent
# This should disable indent
tokens.setKeepLineBreaks(True)
tokens.setFirstLineIndent(True, 1.0, False)
tokens._text = text
tokens.tokenizeText()
assert tokens._blocks == [
(BlockTyp.TEXT, "", "This is text\nspanning multiple\nlines", [], BlockFmt.LEFT),
]
@pytest.mark.core
def testFmtToken_BreakJustify(mockGUI):
"""Test the of processing of justify with breaks."""
project = NWProject()
tokens = BareTokenizer(project)
tokens._handle = TMH
tokens.setJustify(True)
# Applied to all lines when breaks are preserved
tokens._text = "This is text\nspanning multiple\nlines"
tokens.setKeepLineBreaks(True)
tokens.tokenizeText()
assert tokens._blocks == [
(BlockTyp.TEXT, "", "This is text\nspanning multiple\nlines", [], BlockFmt.JUSTIFY),
]
# Turning off breaks should make no difference (see issue #2426)
tokens._text = "This is text\nspanning multiple\nlines"
tokens.setKeepLineBreaks(False)
tokens.tokenizeText()
assert tokens._blocks == [
(BlockTyp.TEXT, "", "This is text spanning multiple lines", [], BlockFmt.JUSTIFY),
]
@pytest.mark.core
def testFmtToken_TextFormat(mockGUI):
"""Test the tokenization of text formats in the Tokenizer class."""