fix(dsl): close margin blocks at the closing tag

Blocks stayed open until the next character arrived, so following text
merged into them and trailing escapes dropped. Close each block right
at its tag and append escaped characters unconditionally.
This commit is contained in:
OneWay committed 2026-09-21 22:08:45 +08:00
1 parent ac9a22dbe1
commit 447d086cdf
1 file changed
+5 -12
@@ -85,7 +85,6 @@ object DslAnnotatedParser {
val lazyRefs = mutableListOf<LazyRef>() val lazyRefs = mutableListOf<LazyRef>()
var accentNext = false var accentNext = false
var currentIndent = 0 var currentIndent = 0
var mClosedPendingBreak = false
var lastAppended: Char? = null var lastAppended: Char? = null
val exampleStyle = SpanStyle(color = colorScheme.secondaryText) val exampleStyle = SpanStyle(color = colorScheme.secondaryText)
val labelStyle = SpanStyle(color = colorScheme.labelText) val labelStyle = SpanStyle(color = colorScheme.labelText)
@@ -116,7 +115,6 @@ object DslAnnotatedParser {
stack.forEach { builder.pushStyle(it) } stack.forEach { builder.pushStyle(it) }
lazyRefs.clear() lazyRefs.clear()
lastAppended = null lastAppended = null
mClosedPendingBreak = false
} }
fun appendChar(char: Char, hard: Boolean = false) { fun appendChar(char: Char, hard: Boolean = false) {
@@ -124,12 +122,6 @@ object DslAnnotatedParser {
if (lastAppended == null || lastAppended == ' ') return if (lastAppended == null || lastAppended == ' ') return
} }
lastAppended = char lastAppended = char
if (mClosedPendingBreak) {
mClosedPendingBreak = false
if (refStack.isEmpty() && !char.isWhitespace()) {
flushBlock()
}
}
builder.append(char) builder.append(char)
if (refStack.isNotEmpty()) { if (refStack.isNotEmpty()) {
refStack.last().second.append(char) refStack.last().second.append(char)
@@ -158,7 +150,7 @@ object DslAnnotatedParser {
when (val char = dsl[i]) { when (val char = dsl[i]) {
'\\' -> { '\\' -> {
if (i + 1 < length) { if (i + 1 < length) {
appendChar(dsl[i + 1]) appendChar(dsl[i + 1], hard = true)
i += 2 i += 2
continue continue
} }
@@ -198,10 +190,11 @@ object DslAnnotatedParser {
} else if (tagName == "'") { } else if (tagName == "'") {
accentNext = false accentNext = false
} }
if (tagName.startsWith("m")) {
mClosedPendingBreak = true
}
pop() pop()
if (tagName.startsWith("m")) {
flushBlock()
currentIndent = 0
}
} else { } else {
when (tagName) { when (tagName) {
"'" -> { "'" -> {