Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
Merge pull request #78 from ashlikatt/fix/styled-text-highlight-crash
Browse files Browse the repository at this point in the history
Fix styled text highlight crash
  • Loading branch information
homchom authored Mar 23, 2024
2 parents 50bf333 + 4184483 commit c54eaff
Showing 1 changed file with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package io.github.homchom.recode.ui.text

import io.github.homchom.recode.util.std.interpolate
import net.kyori.adventure.text.Component
import net.kyori.adventure.text.ComponentLike
import net.kyori.adventure.text.format.TextDecoration
import net.kyori.adventure.text.minimessage.Context
import net.kyori.adventure.text.minimessage.MiniMessage
Expand Down Expand Up @@ -59,7 +58,7 @@ class MiniMessageHighlighter(private val standardTags: TagResolver) {
* - All other valid tags are treated as "literals" and colored gray.
*/
@Suppress("UnstableApiUsage") // TODO: open issue at adventure github
fun highlight(input: String): ComponentLike {
fun highlight(input: String): Component {
// handle the special case of inputs with <reset> parser directives
// TODO: determine if there is a better way to do this
val splitByResets = input.split("<reset>")
Expand All @@ -69,7 +68,7 @@ class MiniMessageHighlighter(private val standardTags: TagResolver) {
literal("<reset>")
}
append(highlight(splitByResets.last()))
}
}.asComponent()

fun TagNode.input() = with(token()) { input.substring(startIndex(), endIndex()) }
fun ValueNode.input() = with(token()) { input.substring(startIndex(), endIndex()) }
Expand Down Expand Up @@ -116,7 +115,7 @@ class MiniMessageHighlighter(private val standardTags: TagResolver) {
instance.deserializeToTree(input)
} catch (e: Exception) {
// https://github.com/KyoriPowered/adventure/issues/1011
return literalText(input, style().red())
return literalText(input, style().red()).asComponent()
}
buildNewInput(root)
return instance.deserialize(newInput.toString())
Expand Down

0 comments on commit c54eaff

Please sign in to comment.