srctree

Robin Linden parent 631faa2b abdc29a7
tui: Fix whitespace-collapsing being ignored

inlinesplit
tui/tui.cpp added: 13, removed: 5, total 8
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2021 Robin Lindén <dev@robinlinden.eu>
// SPDX-FileCopyrightText: 2021-2023 Robin Lindén <dev@robinlinden.eu>
//
// SPDX-License-Identifier: BSD-2-Clause
 
@@ -29,8 +29,8 @@ ftxui::Elements parse_children(layout::LayoutBox const &box) {
ftxui::Element element_from_node(layout::LayoutBox const &box) {
switch (box.type) {
case layout::LayoutType::Inline: {
if (auto const *text = std::get_if<dom::Text>(&box.node->node)) {
return ftxui::paragraph(text->text);
if (auto text = box.text()) {
return ftxui::paragraph(std::string{*text});
}
return hbox(parse_children(box));
}
 
tui/tui_test.cpp added: 13, removed: 5, total 8
@@ -23,5 +23,13 @@ int main() {
a.expect_eq(util::trim(rendered), "Hello, world!");
});
 
s.add_test("Whitespace-collapsing", [](etest::IActions &a) {
dom::Node dom{dom::Element{"div", {}, {dom::Text{"Hello, world!"}}}};
auto style = style::style_tree(dom, {{css::Rule{{"div"}, {{css::PropertyId::Display, "block"}}}}});
auto layout = layout::create_layout(*style, 9000);
auto rendered = tui::render(layout.value());
a.expect_eq(util::trim(rendered), "Hello, world!");
});
 
return s.run();
}