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>()
var accentNext = false
var currentIndent = 0
var mClosedPendingBreak = false
var lastAppended: Char? = null
val exampleStyle = SpanStyle(color = colorScheme.secondaryText)
val labelStyle = SpanStyle(color = colorScheme.labelText)
@@ -116,7 +115,6 @@ object DslAnnotatedParser {
stack.forEach { builder.pushStyle(it) }
lazyRefs.clear()
lastAppended = null
mClosedPendingBreak = false
}
fun appendChar(char: Char, hard: Boolean = false) {
@@ -124,12 +122,6 @@ object DslAnnotatedParser {
if (lastAppended == null || lastAppended == ' ') return
}
lastAppended = char
if (mClosedPendingBreak) {
mClosedPendingBreak = false
if (refStack.isEmpty() && !char.isWhitespace()) {
flushBlock()
}
}
builder.append(char)
if (refStack.isNotEmpty()) {
refStack.last().second.append(char)
@@ -158,7 +150,7 @@ object DslAnnotatedParser {
when (val char = dsl[i]) {
'\\' -> {
if (i + 1 < length) {
appendChar(dsl[i + 1])
appendChar(dsl[i + 1], hard = true)
i += 2
continue
}
@@ -198,10 +190,11 @@ object DslAnnotatedParser {
} else if (tagName == "'") {
accentNext = false
}
if (tagName.startsWith("m")) {
mClosedPendingBreak = true
}
pop()
if (tagName.startsWith("m")) {
flushBlock()
currentIndent = 0
}
} else {
when (tagName) {
"'" -> {