Fix very long text not forcibly wrapping at its max width (#4019)

* fix: Very long text does not forcibly wrap at its max width

* Test that a word longer than the max width breaks to stay within it

---------

Co-authored-by: Dennis Kobert <[email protected]>
This commit is contained in:
Jatin BhartiandDennis Kobert authored and Keavon Chambers committed 2026-11-06 14:51:10 -08:00
1 parent c88d9d366f
commit de08019677
2 files changed
+28 -1

No files matched your search

@@ -1196,6 +1196,32 @@ mod test_text_tool {
(metadata.transform_to_viewport(layer) * frame * Quad::from_box([DVec2::ZERO, DVec2::ONE])).bounding_box()
}
#[tokio::test]
async fn a_word_longer_than_the_max_width_breaks_to_stay_within_it() {
let mut editor = EditorTestUtils::create();
editor.new_document().await;
provide_fonts(&mut editor).await;
let layer = LayerNodeIdentifier::new_unchecked(NodeId::new());
let typesetting = TypesettingConfig {
max_width: Some(100.),
..Default::default()
};
editor
.handle_message(GraphOperationMessage::NewTextLayer {
id: layer.to_node(),
text: "Supercalifragilisticexpialidocious".into(),
font: Font::default(),
typesetting,
parent: LayerNodeIdentifier::ROOT_PARENT,
insert_index: 0,
})
.await;
let [min, max] = editor.active_document().metadata().bounding_box_document(layer).expect("the text should have bounds");
assert!(max.x - min.x <= 100. + 1e-6, "the text is {} wide, wider than its max width of 100", max.x - min.x);
}
#[tokio::test]
async fn a_text_box_stretched_by_its_right_edge_to_near_the_edge_of_a_rectangle_lands_on_it() {
let mut editor = EditorTestUtils::create();
+2 -1
View File
@@ -5,7 +5,7 @@ use core_types::list::List;
use glam::DVec2;
use graphene_resource::{Resource, ResourceHash};
use parley::fontique::{Blob, FamilyId, FontInfo};
use parley::{AlignmentOptions, FontContext, GlyphRun, Layout, LayoutContext, LineHeight, PositionedLayoutItem, StyleProperty};
use parley::{AlignmentOptions, FontContext, GlyphRun, Layout, LayoutContext, LineHeight, OverflowWrap, PositionedLayoutItem, StyleProperty};
use std::collections::HashMap;
use vector_types::Vector;
@@ -134,6 +134,7 @@ impl TextContext {
builder.push_default(StyleProperty::FontStyle(font_info.style()));
builder.push_default(StyleProperty::FontWidth(font_info.width()));
builder.push_default(LineHeight::FontSizeRelative(typesetting.line_height_ratio as f32));
builder.push_default(StyleProperty::OverflowWrap(OverflowWrap::BreakWord));
let mut layout: Layout<()> = builder.build(text);