From d7424f8b8798cc889df3b54748523c1367af2776 Mon Sep 17 00:00:00 2001 From: Hufe921 Date: Wed, 12 Jul 2023 20:58:02 +0800 Subject: [PATCH] fix: limit word break element type #212 --- src/editor/core/draw/Draw.ts | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/editor/core/draw/Draw.ts b/src/editor/core/draw/Draw.ts index d0c543da8..7524d3cd7 100644 --- a/src/editor/core/draw/Draw.ts +++ b/src/editor/core/draw/Draw.ts @@ -1112,15 +1112,20 @@ export class Draw { // 累计行宽 + 当前元素宽度 + 排版宽度(英文单词整体宽度 + 后面标点符号宽度) let curRowWidth = curRow.width + metrics.width if (this.options.wordBreak === WordBreak.BREAK_WORD) { - // 英文单词 - const word = `${preElement?.value || ''}${element.value}` - if (WORD_LIKE_REG.test(word)) { - const { width, endElement } = this.textParticle.measureWord(ctx, elementList, i) - curRowWidth += width - nextElement = endElement + if ( + (!preElement?.type || preElement?.type === ElementType.TEXT) && + (!element.type || element.type === ElementType.TEXT) + ) { + // 英文单词 + const word = `${preElement?.value || ''}${element.value}` + if (WORD_LIKE_REG.test(word)) { + const { width, endElement } = this.textParticle.measureWord(ctx, elementList, i) + curRowWidth += width + nextElement = endElement + } + // 标点符号 + curRowWidth += this.textParticle.measurePunctuationWidth(ctx, nextElement) } - // 标点符号 - curRowWidth += this.textParticle.measurePunctuationWidth(ctx, nextElement) } // 列表信息 if (element.listId) {