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

bug(api): workaround which fixes #849 #861

Merged
merged 1 commit into from
Jan 17, 2023
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.
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 @@ -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