Skip to content

Commit

Permalink
bug(api): workaround which fixes #849
Browse files Browse the repository at this point in the history
  • Loading branch information
kashike committed Jan 15, 2023
1 parent 5318556 commit fa14e85
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@
import net.kyori.adventure.text.format.TextDecoration;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.VisibleForTesting;

final class ComponentCompaction {
@VisibleForTesting
static final boolean SIMPLIFY_STYLE_FOR_BLANK_COMPONENTS = false;

private ComponentCompaction() {
}

Expand Down Expand Up @@ -182,6 +186,12 @@ private static boolean isBlank(final Component component) {
* @return a new, simplified style
*/
private static @NotNull Style simplifyStyleForBlank(final @NotNull Style style, final @Nullable Style parentStyle) {
if (!SIMPLIFY_STYLE_FOR_BLANK_COMPONENTS) {
// todo: can this be fixed a better way?
// https://github.com/KyoriPowered/adventure/issues/849
return style;
}

final Style.Builder builder = style.toBuilder();

// TextColor doesn't affect spaces, unless there is other decoration present
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestFactory;
import org.junit.jupiter.api.condition.DisabledIf;

import static net.kyori.adventure.key.Key.key;
import static net.kyori.adventure.text.Component.empty;
Expand Down Expand Up @@ -317,6 +318,11 @@ void testJoinTextWithChildren() {
assertEquals(expectedCompact, notCompact.compact());
}

private static boolean shouldSkipSimplifyingStyleForBlankComponents() {
return !ComponentCompaction.SIMPLIFY_STYLE_FOR_BLANK_COMPONENTS;
}

@DisabledIf(value = "shouldSkipSimplifyingStyleForBlankComponents", disabledReason = "https://github.com/KyoriPowered/adventure/issues/849") // todo: can this be fixed a better way?
@Test
void testBlankStyleRemoval() {
final String blank = " ";
Expand All @@ -327,6 +333,7 @@ void testBlankStyleRemoval() {
assertEquals(expectedCompact, notCompact.compact());
}

@DisabledIf(value = "shouldSkipSimplifyingStyleForBlankComponents", disabledReason = "https://github.com/KyoriPowered/adventure/issues/849") // todo: can this be fixed a better way?
@Test
void testBlankCompactionWithRemovableStyle() {
final String blank = " ";
Expand All @@ -339,6 +346,7 @@ void testBlankCompactionWithRemovableStyle() {
assertEquals(expectedCompact, notCompact.compact());
}

@DisabledIf(value = "shouldSkipSimplifyingStyleForBlankComponents", disabledReason = "https://github.com/KyoriPowered/adventure/issues/849") // todo: can this be fixed a better way?
@Test
void testBlankCompactionWithManyStyle() {
final String blank = " ";
Expand Down

0 comments on commit fa14e85

Please sign in to comment.