Skip to content

Commit

Permalink
fix: limit word break element type #212
Browse files Browse the repository at this point in the history
  • Loading branch information
Hufe921 committed Jul 12, 2023
1 parent d471165 commit d7424f8
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/editor/core/draw/Draw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit d7424f8

Please sign in to comment.