Skip to content

Commit

Permalink
Fix #455 and add a test for it
Browse files Browse the repository at this point in the history
Stealing zml's thunder but it "appears to work for now"
  • Loading branch information
rymiel authored and zml2008 committed Oct 4, 2021
1 parent 4191e24 commit db09d6b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ static Component compact(final @NotNull Component self, final @Nullable Style pa
}

// propagate the parent style context to children
// by merging this component's style into the parent style
// by merging the parent's style into this component
Style childParentStyle = optimized.style();
if (parentStyle != null) {
childParentStyle = parentStyle.merge(childParentStyle, Style.Merge.Strategy.IF_ABSENT_ON_TARGET);
childParentStyle = childParentStyle.merge(parentStyle, Style.Merge.Strategy.IF_ABSENT_ON_TARGET);
}

// optimize all children
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,4 +277,16 @@ void testCompactWithEmptyRootComponent() {
.append(text("meow").decoration(TextDecoration.BOLD, TextDecoration.State.NOT_SET));
assertEquals(text("meow").decoration(TextDecoration.BOLD, true), c3.compact());
}

@Test
void testStyleMatchingGrandchild() {
final Component notCompact = text("mew", NamedTextColor.RED)
.append(text("mow", NamedTextColor.BLUE)
.append(text("mew", NamedTextColor.RED)));
final Component expectedCompact = text("mew", NamedTextColor.RED)
.append(text("mow", NamedTextColor.BLUE)
.append(text("mew", NamedTextColor.RED)));

assertEquals(expectedCompact, notCompact.compact());
}
}

0 comments on commit db09d6b

Please sign in to comment.