From de0801967702715564f16e552e44dfdcc164f36d Mon Sep 17 00:00:00 2001 From: Jatin Bharti Date: Fri, 6 Nov 2026 22:48:47 +0000 Subject: [PATCH] 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 --- .../messages/tool/tool_messages/text_tool.rs | 26 +++++++++++++++++++ node-graph/nodes/text/src/text_context.rs | 3 ++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/editor/src/messages/tool/tool_messages/text_tool.rs b/editor/src/messages/tool/tool_messages/text_tool.rs index 5f52e72363..742b6a2110 100644 --- a/editor/src/messages/tool/tool_messages/text_tool.rs +++ b/editor/src/messages/tool/tool_messages/text_tool.rs @@ -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(); diff --git a/node-graph/nodes/text/src/text_context.rs b/node-graph/nodes/text/src/text_context.rs index 42ee456a15..4bdc687b89 100644 --- a/node-graph/nodes/text/src/text_context.rs +++ b/node-graph/nodes/text/src/text_context.rs @@ -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);