Skip to content

Commit

Permalink
Merge pull request #835 from KyoriPowered/fix/mm-placeholder-style
Browse files Browse the repository at this point in the history
fix(text-minimessage): Don't strip style of text components in gradients
  • Loading branch information
zml2008 committed Nov 8, 2022
2 parents d82d5ac + 8ea020a commit d0dca11
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Expand Up @@ -118,7 +118,7 @@ public final Component apply(final @NotNull Component current, final int depth)
final int[] holder = new int[1];
for (final PrimitiveIterator.OfInt it = content.codePoints().iterator(); it.hasNext();) {
holder[0] = it.nextInt();
final Component comp = Component.text(new String(holder, 0, 1), this.color());
final Component comp = Component.text(new String(holder, 0, 1), current.style().color(this.color()));
this.advanceColor();
parent.append(comp);
}
Expand Down
Expand Up @@ -25,7 +25,9 @@

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
import net.kyori.adventure.text.minimessage.AbstractTest;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import org.junit.jupiter.api.Test;

import static net.kyori.adventure.text.Component.empty;
Expand Down Expand Up @@ -524,4 +526,20 @@ void testNestedGradientsReallyDontOverrideColors() {

this.assertParsedEquals(expected, input);
}

// https://github.com/KyoriPowered/adventure/issues/790
@Test
void testDecorationsPreserved() {
final Component placeholder = Component.text("b", style(TextDecoration.ITALIC.withState(true)));
final String input = "<gradient>a<placeholder/>c<bold>d</bold>!</gradient>";
final Component expected = Component.textOfChildren(
text("a", WHITE),
text("b", color(0xcccccc), TextDecoration.ITALIC),
text("c", color(0x999999)),
text("d", color(0x666666), BOLD),
text("!", color(0x333333))
);

this.assertParsedEquals(expected, input, Placeholder.component("placeholder", placeholder));
}
}

0 comments on commit d0dca11

Please sign in to comment.