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

Fix styled text highlight crash #78

Merged
merged 3 commits into from
Mar 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading