Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(text-minimessage): Don't strip style of text components in gradients #835

Merged
merged 1 commit into from Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

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