Skip to content

Commit

Permalink
fix(text-block-view): update text listener registration and text pars…
Browse files Browse the repository at this point in the history
…ing for assistant messages

Previously, the text listener was being added to the `getBlock()` which was causing issues during garbage collection. This commit updates the text listener registration to use `block` directly, ensuring that the listener is properly attached to the correct MessageBlock instance. Additionally, the text parsing for assistant messages has been moved inside the if statement where the role of the message is checked, to prevent unnecessary string conversions.
  • Loading branch information
phodal committed Mar 13, 2024
1 parent 8a2c18a commit 011f7ab
Showing 1 changed file with 3 additions and 3 deletions.
Expand Up @@ -32,8 +32,8 @@ class TextBlockView(private val block: MessageBlock) : MessageBlockView {
editorPane.invalidate()
}

getBlock().addTextListener(messagePartTextListener)
messagePartTextListener.onTextChanged(getBlock().getTextContent())
block.addTextListener(messagePartTextListener)
messagePartTextListener.onTextChanged(block.getTextContent())
}

override fun getBlock(): MessageBlock = block
Expand All @@ -56,7 +56,7 @@ class TextBlockView(private val block: MessageBlock) : MessageBlockView {
}

private fun parseText(txt: String): String {
if (getBlock().getMessage().getRole() === ChatRole.Assistant) {
if (block.getMessage().getRole() === ChatRole.Assistant) {
return convertMarkdownToHtml(txt)
}

Expand Down

0 comments on commit 011f7ab

Please sign in to comment.