Skip to content

Commit

Permalink
[6.0.11][publish] Experimental > fix simple component
Browse files Browse the repository at this point in the history
  • Loading branch information
Bkm016 committed Jul 24, 2023
1 parent 0f92333 commit aae2294
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ interface SimpleComponent {

/** 构建为 RawMessage */
fun build(transfer: TextTransfer.() -> Unit = {}): ComponentText

/** 构建为 RawMessage,并上色 */
fun buildColored(transfer: TextTransfer.() -> Unit = {}): ComponentText {
return build { colored() }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,25 @@ class DefaultSimpleComponent(val source: String): SimpleComponent {
/** 构建为 RawMessage */
fun build(transfer: TextTransfer): ComponentText {
val rawMessage = Components.empty()
root.forEach { block ->
var i = 0
var lastBlock: ComponentText? = null
val clone = root.toMutableList()
// 移除最后一个空白文本块
if (clone.isNotEmpty() && clone.last().build(transfer).toRawMessage() == rawMessage.toRawMessage()) {
clone.removeLast()
}
clone.forEach { block ->
if (block is TextBlock.NewLine) {
rawMessage.newLine()
} else {
rawMessage.append(block.build(transfer))
lastBlock = block.build(transfer)
rawMessage.append(lastBlock!!)
}
i++
}
// 直接返回单段文本,避免出现 extra 连套两层的问题
if (i == 1) {
return lastBlock!!
}
return rawMessage
}
Expand Down

0 comments on commit aae2294

Please sign in to comment.