From 137c43f1cb38397178d4f2686affedf09242a0b4 Mon Sep 17 00:00:00 2001 From: "Qinghui.Liu" Date: Wed, 13 Sep 2023 23:13:18 +0800 Subject: [PATCH] feat: breakText method support line wrapping text --- packages/x6-common/src/dom/text.ts | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/packages/x6-common/src/dom/text.ts b/packages/x6-common/src/dom/text.ts index a97eb6ad21b..7f0514bb3aa 100644 --- a/packages/x6-common/src/dom/text.ts +++ b/packages/x6-common/src/dom/text.ts @@ -453,15 +453,12 @@ export function breakText( const delimiter = StringExt.uuid() const splitText: string[] = [] - text.split(eol).map((fragment) => { - splitText.push( - ...breakText( - fragment, - { ...size, height: Number.MAX_SAFE_INTEGER }, - styles, - { ...options, eol: delimiter }, - ).split(delimiter), - ) + text.split(eol).map((line) => { + const part = breakText(line, { ...size, height: Number.MAX_SAFE_INTEGER }, styles, { ...options, eol: delimiter }) + + if (part) { + splitText.push(...part.split(delimiter)) + } }) return splitText.slice(0, maxLines).join(eol)