Skip to content

Commit

Permalink
fix: first row height boundary error #563
Browse files Browse the repository at this point in the history
  • Loading branch information
Hufe921 committed May 13, 2024
1 parent fc55e55 commit 6ada65e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/editor/core/draw/Draw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand Down Expand Up @@ -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 ||
Expand Down Expand Up @@ -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
}
Expand Down
10 changes: 10 additions & 0 deletions src/editor/utils/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
ElementType,
IEditorOption,
IElement,
ImageDisplay,
ListStyle,
ListType,
RowFlex,
Expand All @@ -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,
Expand Down Expand Up @@ -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)
)
}

0 comments on commit 6ada65e

Please sign in to comment.