Skip to content

Truly independent web browser

LibWeb: Find soft wrap opportunities between text nodes

Andreas Kling185490af2f1f
diff --git a/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs b/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs
index af497cb1f88..df962f7733d 100644
--- a/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs
+++ b/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs
@@ -472,6 +472,17 @@ struct InlineLevelIteratorGenerator<'iterator, 'context> {
items: Vec<Item>,
accumulated_inline_size_for_tabs: CssPixels,
previous_chunk_can_break_after: bool,
+ /// The text of the text node before the current one, when nothing but inline box boundaries and out-of-flow
+ /// boxes lies between them.
+ previous_text: Option<&'context [u16]>,
+ /// The number of regional indicators that end the previous text, including any in the text nodes before it.
+ previous_text_regional_indicators: usize,
+ /// The number of regional indicators that end the text before the current text node.
+ regional_indicators_before_text: usize,
+ /// The last code unit of the text before the previous text.
+ code_unit_before_previous_text: Option<u16>,
+ /// The last code unit of the text before the current text node.
+ code_unit_before_text: Option<u16>,
}
impl<'iterator, 'context> InlineLevelIteratorGenerator<'iterator, 'context> {
@@ -495,6 +506,11 @@ impl<'iterator, 'context> InlineLevelIteratorGenerator<'iterator, 'context> {
items: Vec::new(),
accumulated_inline_size_for_tabs: CssPixels::default(),
previous_chunk_can_break_after: false,
+ previous_text: None,
+ previous_text_regional_indicators: 0,
+ regional_indicators_before_text: 0,
+ code_unit_before_previous_text: None,
+ code_unit_before_text: None,
};
iterator.is_unidirectional_left_to_right = iterator.compute_is_unidirectional_left_to_right();
iterator.skip_to_next();
@@ -781,6 +797,17 @@ impl<'iterator, 'context> InlineLevelIteratorGenerator<'iterator, 'context> {
text_type: line_box_fragment::GLYPH_TEXT_TYPE_COMMON,
}
} else {
+ if !text_context.text.is_empty() {
+ let regional_indicators = text_chunker::trailing_regional_indicator_count(text_context.text);
+ // NB: Each regional indicator is a surrogate pair.
+ self.previous_text_regional_indicators = if regional_indicators * 2 == text_context.text.len() {
+ self.regional_indicators_before_text + regional_indicators
+ } else {
+ regional_indicators
+ };
+ self.code_unit_before_previous_text = self.code_unit_before_text;
+ self.previous_text = Some(text_context.text);
+ }
self.text_node_context = None;
self.previous_chunk_can_break_after = false;
self.skip_to_next();
@@ -886,6 +913,37 @@ impl<'iterator, 'context> InlineLevelIteratorGenerator<'iterator, 'context> {
item.is_collapsible_whitespace =
text_context.should_collapse_whitespace && chunk.is_all_whitespace && !generated_empty;
item.can_break_before = self.previous_chunk_can_break_after;
+ // NB: Look for a soft wrap opportunity between the texts of two text nodes, which the chunker of either text
+ // cannot see. This uses the line breaking properties of the text after it.
+ if is_first_chunk {
+ self.regional_indicators_before_text = if self.previous_text.is_some() {
+ self.previous_text_regional_indicators
+ } else {
+ 0
+ };
+ self.code_unit_before_text = self.previous_text.and_then(|text| text.last().copied());
+ }
+ if is_first_chunk
+ && !item.can_break_before
+ && let Some(previous_text) = self.previous_text.take()
+ && style.text_wrap_mode() == text_wrap_mode::WRAP
+ {
+ let line_break_language = if style.line_break() == line_break::LOOSE {
+ self.context().callbacks.arena().text_line_break_language(text_node)
+ } else {
+ text_chunker::LineBreakLanguage::Other
+ };
+ item.can_break_before = text_chunker::soft_wrap_opportunity_between(
+ previous_text,
+ &full_text[chunk.start..],
+ self.code_unit_before_previous_text,
+ self.regional_indicators_before_text,
+ style.word_break(),
+ style.line_break(),
+ line_break_language,
+ );
+ }
+ self.previous_text = None;
self.previous_chunk_can_break_after = chunk.can_break_after;
self.add_extra_box_model_metrics_to_item(&mut item, is_first_chunk, is_last_chunk);
self.text_node_context = Some(text_context);
@@ -929,6 +987,7 @@ impl<'iterator, 'context> InlineLevelIteratorGenerator<'iterator, 'context> {
return Some(item);
}
if facts.is_break_node() {
+ self.previous_text = None;
self.skip_to_next();
return Some(Item::new(ItemType::ForcedBreak, node));
}
@@ -951,6 +1010,7 @@ impl<'iterator, 'context> InlineLevelIteratorGenerator<'iterator, 'context> {
continue;
}
if facts.is_inline_flow_interrupting_block() {
+ self.previous_text = None;
self.skip_to_next();
let mut item = Item::new(ItemType::BlockLevelBox, node);
if self.atomic_sizing == AtomicInlineSizing::Contributions {
@@ -958,6 +1018,7 @@ impl<'iterator, 'context> InlineLevelIteratorGenerator<'iterator, 'context> {
}
return Some(item);
}
+ self.previous_text = None;
return Some(self.generate_element_item(node));
}
}
diff --git a/Libraries/LibWeb/Rust/src/layout/text_chunker.rs b/Libraries/LibWeb/Rust/src/layout/text_chunker.rs
index 47ae50ceca1..60ff167c6b1 100644
--- a/Libraries/LibWeb/Rust/src/layout/text_chunker.rs
+++ b/Libraries/LibWeb/Rust/src/layout/text_chunker.rs
@@ -652,86 +652,102 @@ struct ChunkBreakFlags {
can_break_after: bool,
}
-struct TextChunker<'text> {
- text: &'text [u16],
- frozen_font_list: &'text FrozenFontList,
- grapheme_segmenter: GraphemeSegmenter,
- line_segmenter: LineSegmenter<'text>,
- word_break: u8,
- allow_conditional_japanese_starters: bool,
- font_variant_emoji: u8,
- should_collapse_whitespace: bool,
- break_after_preserved_tabs: bool,
- should_wrap_lines: bool,
- should_respect_linebreaks: bool,
- unidirectional_ltr: bool,
- splits_at_orientation_changes: bool,
- current_index: usize,
- last_non_whitespace_font: Option<FontHandle>,
+fn is_regional_indicator(code_point: u32) -> bool {
+ (0x1F1E6..=0x1F1FF).contains(&code_point)
}
-impl<'text> TextChunker<'text> {
- fn new(inputs: TextChunkInputs<'text>) -> Self {
- // NB: Apply CJ tailoring to word-break classification as well as to ICU's line segmenter.
- let allow_conditional_japanese_starters = matches!(inputs.line_break, line_break::NORMAL | line_break::LOOSE);
- Self {
- text: inputs.text,
- frozen_font_list: inputs.frozen_font_list,
- grapheme_segmenter: GraphemeSegmenter::new(inputs.text),
- line_segmenter: LineSegmenter::new(inputs.text, inputs.line_break, inputs.line_break_language),
- word_break: inputs.word_break,
- allow_conditional_japanese_starters,
- font_variant_emoji: inputs.font_variant_emoji,
- should_collapse_whitespace: matches!(
- inputs.white_space_collapse,
- white_space_collapse::COLLAPSE | white_space_collapse::PRESERVE_BREAKS
- ),
- break_after_preserved_tabs: inputs.white_space_collapse == white_space_collapse::BREAK_SPACES
- && inputs.should_wrap_lines,
- should_wrap_lines: inputs.should_wrap_lines,
- should_respect_linebreaks: inputs.should_respect_linebreaks,
- unidirectional_ltr: inputs.unidirectional_ltr,
- splits_at_orientation_changes: inputs.splits_at_orientation_changes,
- current_index: 0,
- last_non_whitespace_font: None,
- }
+/// The number of regional indicators at the end of a text.
+pub(crate) fn trailing_regional_indicator_count(text: &[u16]) -> usize {
+ let mut index = text.len();
+ let mut count = 0;
+ while index > 0 && is_regional_indicator(previous_code_point_at(text, &mut index)) {
+ count += 1;
}
+ count
+}
- fn current_code_point(&self) -> u32 {
- code_point_at(self.text, self.current_index)
+/// Whether there is a soft wrap opportunity between the end of `before` and the start of `after`, such as the texts
+/// of two text nodes that follow each other on a line. `code_unit_before` is the last code unit of the text before
+/// `before`, if any. `regional_indicators_before` is the number of regional indicators that end `before`, including
+/// any in text before it.
+pub(crate) fn soft_wrap_opportunity_between(
+ before: &[u16],
+ after: &[u16],
+ code_unit_before: Option<u16>,
+ regional_indicators_before: usize,
+ word_break: u8,
+ line_break: u8,
+ line_break_language: LineBreakLanguage,
+) -> bool {
+ let (Some(&last), Some(&first)) = (before.last(), after.first()) else {
+ return false;
+ };
+ // NB: Whitespace gives its own soft wrap opportunities.
+ if (last <= 0x7f && code_point_is_ascii_space(u32::from(last)))
+ || (first <= 0x7f && code_point_is_ascii_space(u32::from(first)))
+ {
+ return false;
}
-
- fn current_text_type(&self) -> u8 {
- if self.unidirectional_ltr {
- return line_box_fragment::GLYPH_TEXT_TYPE_LTR;
- }
- text_type_for_code_point(self.current_code_point())
+ // NB: Only the number of regional indicators before the boundary tells whether it splits a flag, and they can
+ // reach further back than the context below.
+ if regional_indicators_before > 0 && is_regional_indicator(code_point_at(after, 0)) {
+ return regional_indicators_before.is_multiple_of(2);
}
-
- fn current_code_point_is_upright(&self) -> bool {
- self.splits_at_orientation_changes && code_point_is_upright_in_mixed_orientation(self.current_code_point())
+ // NB: A few code points on each side of the boundary are enough context to find a soft wrap opportunity there.
+ const CONTEXT_LENGTH: usize = 8;
+ let mut before_start = before.len().saturating_sub(CONTEXT_LENGTH);
+ if before_start > 0 && is_utf16_low_surrogate(before[before_start]) {
+ before_start -= 1;
}
-
- fn next_grapheme_boundary(&self) -> usize {
- self.grapheme_segmenter
- .next_boundary(self.current_index, false)
- .unwrap_or(self.text.len())
+ let mut after_end = after.len().min(CONTEXT_LENGTH);
+ if after_end < after.len() && is_utf16_low_surrogate(after[after_end]) {
+ after_end += 1;
}
-
- fn is_collapsible(&self, code_point: u32) -> bool {
- self.should_collapse_whitespace && code_point_is_ascii_space(code_point)
+ let mut text = Vec::with_capacity(before.len() - before_start + after_end + 1);
+ // NB: Some rules look at the code point before the last one of `before`, which can be in the text before it.
+ if before_start == 0
+ && let Some(code_unit) = code_unit_before
+ && !is_utf16_low_surrogate(code_unit)
+ {
+ text.push(code_unit);
+ }
+ text.extend_from_slice(&before[before_start..]);
+ let boundary = text.len();
+ text.extend_from_slice(&after[..after_end]);
+ // OPTIMIZATION: Printable ASCII on both sides needs no line segmenter.
+ if word_break != word_break::BREAK_ALL
+ && let Some(is_boundary) = ascii_line_break_at(&text, boundary)
+ {
+ return is_boundary;
}
+ LineBreaker::new(&text, word_break, line_break, line_break_language).is_at_line_break_opportunity(boundary)
+}
- fn is_at_line_break_opportunity(&self) -> bool {
- if !self.should_wrap_lines {
- return false;
+/// Finds the soft wrap opportunities of a text.
+struct LineBreaker<'text> {
+ text: &'text [u16],
+ line_segmenter: LineSegmenter<'text>,
+ word_break: u8,
+ allow_conditional_japanese_starters: bool,
+}
+
+impl<'text> LineBreaker<'text> {
+ fn new(text: &'text [u16], word_break: u8, line_break: u8, line_break_language: LineBreakLanguage) -> Self {
+ Self {
+ text,
+ line_segmenter: LineSegmenter::new(text, line_break, line_break_language),
+ word_break,
+ // NB: Apply CJ tailoring to word-break classification as well as to ICU's line segmenter.
+ allow_conditional_japanese_starters: matches!(line_break, line_break::NORMAL | line_break::LOOSE),
}
+ }
+ fn is_at_line_break_opportunity(&self, index: usize) -> bool {
let get_previous_code_point = || -> Option<u32> {
- if self.current_index == 0 {
+ if index == 0 {
return None;
}
- let mut index = self.current_index;
+ let mut index = index;
let mut previous_code_point = previous_code_point_at(self.text, &mut index);
while line_break_class(previous_code_point, self.allow_conditional_japanese_starters)
== line_break_class::COMBINING_MARK
@@ -744,17 +760,17 @@ impl<'text> TextChunker<'text> {
let is_at_line_segmenter_boundary = || {
if self.word_break != word_break::BREAK_ALL
- && let Some(is_boundary) = ascii_line_break_at(self.text, self.current_index)
+ && let Some(is_boundary) = ascii_line_break_at(self.text, index)
{
return is_boundary;
}
- self.line_segmenter.next_boundary(self.current_index, true) == Some(self.current_index)
+ self.line_segmenter.next_boundary(index, true) == Some(index)
};
match self.word_break {
word_break::NORMAL | word_break::BREAK_WORD => is_at_line_segmenter_boundary(),
word_break::BREAK_ALL => {
- if self.current_index >= self.text.len() {
+ if index >= self.text.len() {
return false;
}
use line_break_class::*;
@@ -766,14 +782,14 @@ impl<'text> TextChunker<'text> {
};
if let Some(previous_code_point) = get_previous_code_point()
&& breaks_anywhere(previous_code_point)
- && breaks_anywhere(self.current_code_point())
+ && breaks_anywhere(code_point_at(self.text, index))
{
return true;
}
is_at_line_segmenter_boundary()
}
word_break::KEEP_ALL => {
- if self.current_index >= self.text.len() {
+ if index >= self.text.len() {
return false;
}
use line_break_class::*;
@@ -785,7 +801,7 @@ impl<'text> TextChunker<'text> {
};
if let Some(previous_code_point) = get_previous_code_point()
&& keeps_together(previous_code_point)
- && keeps_together(self.current_code_point())
+ && keeps_together(code_point_at(self.text, index))
{
return false;
}
@@ -794,6 +810,80 @@ impl<'text> TextChunker<'text> {
_ => unreachable!("invalid word-break value"),
}
}
+}
+
+struct TextChunker<'text> {
+ text: &'text [u16],
+ frozen_font_list: &'text FrozenFontList,
+ grapheme_segmenter: GraphemeSegmenter,
+ line_breaker: LineBreaker<'text>,
+ font_variant_emoji: u8,
+ should_collapse_whitespace: bool,
+ break_after_preserved_tabs: bool,
+ should_wrap_lines: bool,
+ should_respect_linebreaks: bool,
+ unidirectional_ltr: bool,
+ splits_at_orientation_changes: bool,
+ current_index: usize,
+ last_non_whitespace_font: Option<FontHandle>,
+}
+
+impl<'text> TextChunker<'text> {
+ fn new(inputs: TextChunkInputs<'text>) -> Self {
+ Self {
+ text: inputs.text,
+ frozen_font_list: inputs.frozen_font_list,
+ grapheme_segmenter: GraphemeSegmenter::new(inputs.text),
+ line_breaker: LineBreaker::new(
+ inputs.text,
+ inputs.word_break,
+ inputs.line_break,
+ inputs.line_break_language,
+ ),
+ font_variant_emoji: inputs.font_variant_emoji,
+ should_collapse_whitespace: matches!(
+ inputs.white_space_collapse,
+ white_space_collapse::COLLAPSE | white_space_collapse::PRESERVE_BREAKS
+ ),
+ break_after_preserved_tabs: inputs.white_space_collapse == white_space_collapse::BREAK_SPACES
+ && inputs.should_wrap_lines,
+ should_wrap_lines: inputs.should_wrap_lines,
+ should_respect_linebreaks: inputs.should_respect_linebreaks,
+ unidirectional_ltr: inputs.unidirectional_ltr,
+ splits_at_orientation_changes: inputs.splits_at_orientation_changes,
+ current_index: 0,
+ last_non_whitespace_font: None,
+ }
+ }
+
+ fn current_code_point(&self) -> u32 {
+ code_point_at(self.text, self.current_index)
+ }
+
+ fn current_text_type(&self) -> u8 {
+ if self.unidirectional_ltr {
+ return line_box_fragment::GLYPH_TEXT_TYPE_LTR;
+ }
+ text_type_for_code_point(self.current_code_point())
+ }
+
+ fn current_code_point_is_upright(&self) -> bool {
+ self.splits_at_orientation_changes && code_point_is_upright_in_mixed_orientation(self.current_code_point())
+ }
+
+ fn next_grapheme_boundary(&self) -> usize {
+ self.grapheme_segmenter
+ .next_boundary(self.current_index, false)
+ .unwrap_or(self.text.len())
+ }
+
+ fn is_collapsible(&self, code_point: u32) -> bool {
+ self.should_collapse_whitespace && code_point_is_ascii_space(code_point)
+ }
+
+ fn is_at_line_break_opportunity(&self) -> bool {
+ self.should_wrap_lines && self.line_breaker.is_at_line_break_opportunity(self.current_index)
+ }
fn emoji_presentation_at(&self, code_unit_offset: usize, code_point: u32) -> EmojiPresentation {
let next_offset = code_unit_offset + code_unit_length_for_code_point(code_point);
diff --git a/Tests/LibWeb/Layout/expected/soft-wrap-opportunity-after-hyphen-after-space.txt b/Tests/LibWeb/Layout/expected/soft-wrap-opportunity-after-hyphen-after-space.txt
index 5c2769e861c..2ef617a4bfc 100644
--- a/Tests/LibWeb/Layout/expected/soft-wrap-opportunity-after-hyphen-after-space.txt
+++ b/Tests/LibWeb/Layout/expected/soft-wrap-opportunity-after-hyphen-after-space.txt
@@ -10,26 +10,24 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children
BlockContainer <(anonymous)> at [8,38] [0+0+0 784 0+0+0] [0+0+0 0 0+0+0] children: inline
TextNode <#text> (not painted)
BlockContainer <div> at [8,38] [0+0+0 110 0+0+674] [0+0+0 20 0+0+10] children: inline
- frag 0 from TextNode start: 0, length: 3, rect: [8,38 30x10] baseline: 8
- "aaa"
- frag 1 from TextNode start: 0, length: 9, rect: [78,48 90x10] baseline: 8
+ frag 0 from TextNode start: 0, length: 4, rect: [8,38 40x10] baseline: 8
+ "aaa "
+ frag 1 from TextNode start: 0, length: 9, rect: [8,48 90x10] baseline: 8
"efficient"
TextNode <#text> (not painted)
- InlineNode <b> at [8,48] [0+0+0 70 0+0+0] [0+0+0 10 0+0+0]
- frag 0 from TextNode start: 0, length: 7, rect: [8,48 70x10] baseline: 8
+ InlineNode <b> at [48,38] [0+0+0 70 0+0+0] [0+0+0 10 0+0+0]
+ frag 0 from TextNode start: 0, length: 7, rect: [48,38 70x10] baseline: 8
"memory-"
TextNode <#text> (not painted)
TextNode <#text> (not painted)
BlockContainer <(anonymous)> at [8,68] [0+0+0 784 0+0+0] [0+0+0 0 0+0+0] children: inline
TextNode <#text> (not painted)
BlockContainer <div> at [8,68] [0+0+0 110 0+0+674] [0+0+0 20 0+0+10] children: inline
- frag 0 from TextNode start: 0, length: 3, rect: [8,68 30x10] baseline: 8
- "aaa"
- frag 1 from TextNode start: 4, length: 7, rect: [8,78 70x10] baseline: 8
- "memory-"
+ frag 0 from TextNode start: 0, length: 11, rect: [8,68 110x10] baseline: 8
+ "aaa memory-"
TextNode <#text> (not painted)
- InlineNode <b> at [78,78] [0+0+0 90 0+0+0] [0+0+0 10 0+0+0]
- frag 0 from TextNode start: 0, length: 9, rect: [78,78 90x10] baseline: 8
+ InlineNode <b> at [8,78] [0+0+0 90 0+0+0] [0+0+0 10 0+0+0]
+ frag 0 from TextNode start: 0, length: 9, rect: [8,78 90x10] baseline: 8
"efficient"
TextNode <#text> (not painted)
BlockContainer <(anonymous)> at [8,98] [0+0+0 784 0+0+0] [0+0+0 0 0+0+0] children: inline
diff --git a/Tests/LibWeb/Layout/expected/soft-wrap-opportunity-after-hyphen-between-text-nodes.txt b/Tests/LibWeb/Layout/expected/soft-wrap-opportunity-after-hyphen-between-text-nodes.txt
new file mode 100644
index 00000000000..a057c82888d
--- /dev/null
+++ b/Tests/LibWeb/Layout/expected/soft-wrap-opportunity-after-hyphen-between-text-nodes.txt
@@ -0,0 +1,50 @@
+Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children: not-inline
+ BlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 176 0+0+0] [BFC] children: not-inline
+ BlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 158 0+0+8] children: not-inline
+ BlockContainer <div> at [8,8] [0+0+0 0 0+0+784] [0+0+0 32 0+0+10] children: inline
+ frag 0 from TextNode start: 0, length: 4, rect: [8,8 34.1875x16] baseline: 12.796875
+ "abc-"
+ frag 1 from TextNode start: 4, length: 1, rect: [8,24 9.09375x16] baseline: 12.796875
+ "3"
+ TextNode <#text> (not painted)
+ BlockContainer <(anonymous)> at [8,50] [0+0+0 784 0+0+0] [0+0+0 0 0+0+0] children: inline
+ TextNode <#text> (not painted)
+ BlockContainer <div> at [8,50] [0+0+0 0 0+0+784] [0+0+0 32 0+0+10] children: inline
+ frag 0 from TextNode start: 0, length: 3, rect: [8,50 27.703125x16] baseline: 12.796875
+ "abc"
+ frag 1 from TextNode start: 0, length: 1, rect: [8,66 9.09375x16] baseline: 12.796875
+ "3"
+ TextNode <#text> (not painted)
+ InlineNode <b> at [35.703125,50] [0+0+0 6.484375 0+0+0] [0+0+0 16 0+0+0]
+ frag 0 from TextNode start: 0, length: 1, rect: [35.703125,50 6.484375x16] baseline: 12.796875
+ "-"
+ TextNode <#text> (not painted)
+ TextNode <#text> (not painted)
+ BlockContainer <(anonymous)> at [8,92] [0+0+0 784 0+0+0] [0+0+0 0 0+0+0] children: inline
+ TextNode <#text> (not painted)
+ BlockContainer <div> at [8,92] [0+0+0 0 0+0+784] [0+0+0 32 0+0+10] children: inline
+ frag 0 from TextNode start: 0, length: 4, rect: [8,92 34.1875x16] baseline: 12.796875
+ "abc-"
+ TextNode <#text> (not painted)
+ InlineNode <b> at [8,108] [0+0+0 9.09375 0+0+0] [0+0+0 16 0+0+0]
+ frag 0 from TextNode start: 0, length: 1, rect: [8,108 9.09375x16] baseline: 12.796875
+ "3"
+ TextNode <#text> (not painted)
+ BlockContainer <(anonymous)> at [8,134] [0+0+0 784 0+0+0] [0+0+0 0 0+0+0] children: inline
+ TextNode <#text> (not painted)
+ BlockContainer <div> at [8,134] [0+0+0 0 0+0+784] [0+0+0 32 0+0+10] children: inline
+ frag 0 from TextNode start: 0, length: 1, rect: [8,134 6.484375x16] baseline: 12.796875
+ "-"
+ frag 1 from TextNode start: 0, length: 1, rect: [14.484375,150 9.09375x16] baseline: 12.796875
+ "3"
+ TextNode <#text> (not painted)
+ InlineNode <b> at [8,150] [0+0+0 6.484375 0+0+0] [0+0+0 16 0+0+0]
+ frag 0 from TextNode start: 0, length: 1, rect: [8,150 6.484375x16] baseline: 12.796875
+ "-"
+ TextNode <#text> (not painted)
+ TextNode <#text> (not painted)
+ BlockContainer <(anonymous)> at [8,176] [0+0+0 784 0+0+0] [0+0+0 0 0+0+0] children: inline
+ TextNode <#text> (not painted)
+
+SC for Viewport<#document> [0,0 800x600] (z-index: auto)
+ SC for BlockContainer<HTML> [0,0 800x176] (z-index: auto)
diff --git a/Tests/LibWeb/Layout/expected/soft-wrap-opportunity-between-regional-indicators.txt b/Tests/LibWeb/Layout/expected/soft-wrap-opportunity-between-regional-indicators.txt
new file mode 100644
index 00000000000..f631d4ddd63
--- /dev/null
+++ b/Tests/LibWeb/Layout/expected/soft-wrap-opportunity-between-regional-indicators.txt
@@ -0,0 +1,39 @@
+Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children: not-inline
+ BlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 124 0+0+0] [BFC] children: not-inline
+ BlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 106 0+0+8] children: not-inline
+ BlockContainer <div> at [8,8] [0+0+0 0 0+0+784] [0+0+0 64 0+0+10] children: inline
+ frag 0 from TextNode start: 0, length: 1, rect: [8,8 9.703125x16] baseline: 12.796875
+ "x"
+ frag 1 from TextNode start: 1, length: 4, rect: [8,24 20.3125x16] baseline: 12.796875
+ "๐Ÿ‡บ๐Ÿ‡ธ"
+ frag 2 from TextNode start: 5, length: 4, rect: [8,40 20.3125x16] baseline: 12.796875
+ "๐Ÿ‡บ๐Ÿ‡ธ"
+ frag 3 from TextNode start: 9, length: 2, rect: [8,56 20.3125x16] baseline: 12.796875
+ "๐Ÿ‡บ"
+ TextNode <#text> (not painted)
+ InlineNode <b> at [28.3125,56] [0+0+0 20.3125 0+0+0] [0+0+0 16 0+0+0]
+ frag 0 from TextNode start: 0, length: 2, rect: [28.3125,56 20.3125x16] baseline: 12.796875
+ "๐Ÿ‡ธ"
+ TextNode <#text> (not painted)
+ BlockContainer <(anonymous)> at [8,82] [0+0+0 784 0+0+0] [0+0+0 0 0+0+0] children: inline
+ TextNode <#text> (not painted)
+ BlockContainer <div> at [8,82] [0+0+0 0 0+0+784] [0+0+0 32 0+0+10] children: inline
+ frag 0 from TextNode start: 0, length: 2, rect: [8,82 20.3125x16] baseline: 12.796875
+ "๐Ÿ‡บ"
+ frag 1 from TextNode start: 0, length: 2, rect: [8,98 20.3125x16] baseline: 12.796875
+ "๐Ÿ‡บ"
+ TextNode <#text> (not painted)
+ InlineNode <b> at [28.3125,82] [0+0+0 20.3125 0+0+0] [0+0+0 16 0+0+0]
+ frag 0 from TextNode start: 0, length: 2, rect: [28.3125,82 20.3125x16] baseline: 12.796875
+ "๐Ÿ‡ธ"
+ TextNode <#text> (not painted)
+ TextNode <#text> (not painted)
+ InlineNode <b> at [28.3125,98] [0+0+0 20.3125 0+0+0] [0+0+0 16 0+0+0]
+ frag 0 from TextNode start: 0, length: 2, rect: [28.3125,98 20.3125x16] baseline: 12.796875
+ "๐Ÿ‡ธ"
+ TextNode <#text> (not painted)
+ BlockContainer <(anonymous)> at [8,124] [0+0+0 784 0+0+0] [0+0+0 0 0+0+0] children: inline
+ TextNode <#text> (not painted)
+
+SC for Viewport<#document> [0,0 800x600] (z-index: auto)
+ SC for BlockContainer<HTML> [0,0 800x124] (z-index: auto)
diff --git a/Tests/LibWeb/Layout/input/soft-wrap-opportunity-after-hyphen-between-text-nodes.html b/Tests/LibWeb/Layout/input/soft-wrap-opportunity-after-hyphen-between-text-nodes.html
new file mode 100644
index 00000000000..69db14e3750
--- /dev/null
+++ b/Tests/LibWeb/Layout/input/soft-wrap-opportunity-after-hyphen-between-text-nodes.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<style>
+ div {
+ width: 0;
+ margin-bottom: 10px;
+ }
+</style>
+<div>abc-3</div>
+<div>abc<b>-</b>3</div>
+<div>abc-<b>3</b></div>
+<div>-<b>-</b>3</div>
diff --git a/Tests/LibWeb/Layout/input/soft-wrap-opportunity-between-regional-indicators.html b/Tests/LibWeb/Layout/input/soft-wrap-opportunity-between-regional-indicators.html
new file mode 100644
index 00000000000..b2315f2a8fd
--- /dev/null
+++ b/Tests/LibWeb/Layout/input/soft-wrap-opportunity-between-regional-indicators.html
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<style>
+ div {
+ width: 0;
+ margin-bottom: 10px;
+ }
+</style>
+<div>x&#x1F1FA;&#x1F1F8;&#x1F1FA;&#x1F1F8;&#x1F1FA;<b>&#x1F1F8;</b></div>
+<div>&#x1F1FA;<b>&#x1F1F8;</b>&#x1F1FA;<b>&#x1F1F8;</b></div>