Skip to content
Open
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
3 changes: 1 addition & 2 deletions parley/src/resolve/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ impl<B: Brush> TreeStyleBuilder<B> {
style_id: None,
});
self.current_span = self.tree.len() - 1;
self.is_span_first = true;
}

pub(crate) fn push_style_modification_span(
Expand All @@ -182,7 +181,7 @@ impl<B: Brush> TreeStyleBuilder<B> {
}

pub(crate) fn pop_style_span(&mut self) {
self.push_uncommitted_text(true);
self.push_uncommitted_text(false);

self.current_span = self.tree[self.current_span]
.parent
Expand Down
26 changes: 25 additions & 1 deletion parley/src/tests/test_builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use super::utils::{ColorBrush, asserts::assert_eq_layout_data};
use crate::{
BaseDirection, FontContext, FontFamily, FontFeatures, FontVariations, Layout, LayoutContext,
LineHeight, OverflowWrap, RangedBuilder, StyleProperty, StyleRunBuilder, TextStyle,
TextWrapMode, TreeBuilder, WordBreak,
TextWrapMode, TreeBuilder, WhiteSpaceCollapse, WordBreak,
};

// TODO: `FONT_FAMILY_LIST`, `load_fonts`, and `create_font_context` are
Expand Down Expand Up @@ -649,6 +649,30 @@ fn builders_crlf_counts_as_single_line_break() {
);
}

/// Whitespace collapsing must not remove whitespace at style span boundaries:
/// a span's leading/trailing spaces are only trimmed when they are at the start
/// of the text or follow existing whitespace.
#[test]
fn tree_builder_collapse_preserves_whitespace_at_span_boundaries() {
let mut fcx = create_font_context();
let mut lcx: LayoutContext<ColorBrush> = LayoutContext::new();
let root_style = create_root_style();

let mut tb = lcx.tree_builder(&mut fcx, 1.0, false, &root_style);
tb.set_white_space_mode(WhiteSpaceCollapse::Collapse);
tb.push_text(" Singer-songwriter");
tb.push_style_modification_span(&[StyleProperty::FontSize(40.)]);
tb.push_text("\u{a0} · ");
tb.pop_style_span();
tb.push_text("actress");
let (_, text) = tb.build();

assert_eq!(
text, "Singer-songwriter\u{a0} · actress",
"spaces inside a style span must survive whitespace collapsing"
);
}

/// A CRLF whose `\r` and `\n` land in different shaped runs (because a style
/// change starts at the `\n`) must still coalesce into a single hard break.
#[test]
Expand Down