From 6ada65e7680b8ca71657bc643f0eb807d9b78f5f Mon Sep 17 00:00:00 2001 From: Hufe921 Date: Mon, 13 May 2024 22:17:24 +0800 Subject: [PATCH] fix: first row height boundary error #563 --- src/editor/core/draw/Draw.ts | 21 ++++++++++----------- src/editor/utils/element.ts | 10 ++++++++++ 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/editor/core/draw/Draw.ts b/src/editor/core/draw/Draw.ts index b88f5606..56b24574 100644 --- a/src/editor/core/draw/Draw.ts +++ b/src/editor/core/draw/Draw.ts @@ -63,7 +63,11 @@ import { WordBreak } from '../../dataset/enum/Editor' import { Control } from './control/Control' -import { getSlimCloneElementList, zipElementList } from '../../utils/element' +import { + getIsInlineElement, + getSlimCloneElementList, + zipElementList +} from '../../utils/element' import { CheckboxParticle } from './particle/CheckboxParticle' import { RadioParticle } from './particle/RadioParticle' import { DeepRequired, IPadding } from '../../interface/Common' @@ -84,7 +88,6 @@ import { Zone } from '../zone/Zone' import { Footer } from './frame/Footer' import { IMAGE_ELEMENT_TYPE, - INLINE_ELEMENT_TYPE, TEXTLIKE_ELEMENT_TYPE } from '../../dataset/constant/Element' import { ListParticle } from './particle/ListParticle' @@ -1599,14 +1602,6 @@ export class Draw { if (isForceBreak || isWidthNotEnough) { // 换行原因:宽度不足 curRow.isWidthNotEnough = isWidthNotEnough && !isForceBreak - // 减小行元素前第一行空行行高 - if ( - curRow.startIndex === 0 && - curRow.elementList.length === 1 && - INLINE_ELEMENT_TYPE.includes(element.type!) - ) { - curRow.height = defaultBasicRowMarginHeight - } // 两端对齐、分散对齐 if ( preElement?.rowFlex === RowFlex.JUSTIFY || @@ -1665,7 +1660,11 @@ export class Draw { rowList.push(row) } else { curRow.width += metrics.width - if (curRow.height < height) { + // 减小行元素前第一行空行行高 + if (i === 0 && getIsInlineElement(elementList[1])) { + curRow.height = defaultBasicRowMarginHeight + curRow.ascent = defaultBasicRowMarginHeight + } else if (curRow.height < height) { curRow.height = height curRow.ascent = ascent } diff --git a/src/editor/utils/element.ts b/src/editor/utils/element.ts index ccf8ef8d..e17bf647 100644 --- a/src/editor/utils/element.ts +++ b/src/editor/utils/element.ts @@ -11,6 +11,7 @@ import { ElementType, IEditorOption, IElement, + ImageDisplay, ListStyle, ListType, RowFlex, @@ -23,6 +24,7 @@ import { CONTROL_STYLE_ATTR, EDITOR_ELEMENT_CONTEXT_ATTR, EDITOR_ELEMENT_ZIP_ATTR, + INLINE_ELEMENT_TYPE, INLINE_NODE_NAME, TABLE_CONTEXT_ATTR, TABLE_TD_ZIP_ATTR, @@ -1377,3 +1379,11 @@ export function getSlimCloneElementList(elementList: IElement[]) { 'style' ]) } + +export function getIsInlineElement(element?: IElement) { + return ( + !!element?.type && + (INLINE_ELEMENT_TYPE.includes(element.type) || + element.imgDisplay === ImageDisplay.INLINE) + ) +}