feat: wrap within list item

pr675
Hufe921 3 years ago
parent c5699bcb4c
commit 69750a115a

@ -1043,7 +1043,7 @@ export class Draw {
if (element.listId) {
if (element.listId !== listId) {
listIndex = 0
} else if (element.value === ZERO) {
} else if (element.value === ZERO && !element.listWrap) {
listIndex++
}
}

@ -75,7 +75,7 @@ export class ListParticle {
public drawListStyle(ctx: CanvasRenderingContext2D, row: IRow, position: IElementPosition) {
const { elementList, offsetX, listIndex, ascent } = row
const startElement = elementList[0]
if (startElement.value !== ZERO) return
if (startElement.value !== ZERO || startElement.listWrap) return
let text = ''
if (startElement.listType === ListType.UL) {
if (startElement.listStyle) {

@ -77,8 +77,13 @@ export function keydown(evt: KeyboardEvent, host: CanvasEvent) {
const enterText: IElement = {
value: ZERO
}
// 标题结尾处回车无需格式化
const startElement = elementList[startIndex]
const endElement = elementList[endIndex]
// 列表块内换行
if (evt.shiftKey && startElement.listId) {
enterText.listWrap = true
}
// 标题结尾处回车无需格式化
if (!(endElement.titleId && endElement.titleId !== elementList[endIndex + 1]?.titleId)) {
formatElementContext(elementList, [enterText], startIndex)
}

@ -55,7 +55,8 @@ export const EDITOR_ELEMENT_ZIP_ATTR: Array<keyof IElement> = [
'block',
'level',
'listType',
'listStyle'
'listStyle',
'listWrap'
]
export const EDITOR_ELEMENT_CONTEXT_ATTR: Array<keyof IElement> = [

@ -43,6 +43,7 @@ export interface IListElement {
listType?: ListType;
listStyle?: ListStyle;
listId?: string;
listWrap?: boolean;
}
export interface ITableAttr {

@ -110,18 +110,24 @@ export function writeElementList(elementList: IElement[], options: DeepRequired<
const zipList = zipElementList(element.valueList!)
for (let z = 0; z < zipList.length; z++) {
const zipElement = zipList[z]
const zipValueList = zipElement.value.split('\n')
for (let c = 0; c < zipValueList.length; c++) {
if (c > 0) {
curListIndex += 1
}
const value = zipValueList[c]
if (zipElement.listWrap) {
const listElementList = listElementListMap.get(curListIndex) || []
listElementList.push({
...zipElement,
value,
})
listElementList.push(zipElement)
listElementListMap.set(curListIndex, listElementList)
} else {
const zipValueList = zipElement.value.split('\n')
for (let c = 0; c < zipValueList.length; c++) {
if (c > 0) {
curListIndex += 1
}
const value = zipValueList[c]
const listElementList = listElementListMap.get(curListIndex) || []
listElementList.push({
...zipElement,
value,
})
listElementListMap.set(curListIndex, listElementList)
}
}
}
listElementListMap.forEach(listElementList => {
@ -264,6 +270,11 @@ export function getElementListByHTML(htmlText: string, options: IGetElementListB
}
listNode.querySelectorAll('li').forEach(li => {
const liValueList = getElementListByHTML(li.innerHTML, options)
liValueList.forEach(list => {
if (list.value === '\n') {
list.listWrap = true
}
})
liValueList.unshift({
value: '\n'
})

Loading…
Cancel
Save