feat: wrap within list item
This commit is contained in:
@@ -1043,7 +1043,7 @@ export class Draw {
|
|||||||
if (element.listId) {
|
if (element.listId) {
|
||||||
if (element.listId !== listId) {
|
if (element.listId !== listId) {
|
||||||
listIndex = 0
|
listIndex = 0
|
||||||
} else if (element.value === ZERO) {
|
} else if (element.value === ZERO && !element.listWrap) {
|
||||||
listIndex++
|
listIndex++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ export class ListParticle {
|
|||||||
public drawListStyle(ctx: CanvasRenderingContext2D, row: IRow, position: IElementPosition) {
|
public drawListStyle(ctx: CanvasRenderingContext2D, row: IRow, position: IElementPosition) {
|
||||||
const { elementList, offsetX, listIndex, ascent } = row
|
const { elementList, offsetX, listIndex, ascent } = row
|
||||||
const startElement = elementList[0]
|
const startElement = elementList[0]
|
||||||
if (startElement.value !== ZERO) return
|
if (startElement.value !== ZERO || startElement.listWrap) return
|
||||||
let text = ''
|
let text = ''
|
||||||
if (startElement.listType === ListType.UL) {
|
if (startElement.listType === ListType.UL) {
|
||||||
if (startElement.listStyle) {
|
if (startElement.listStyle) {
|
||||||
|
|||||||
@@ -77,8 +77,13 @@ export function keydown(evt: KeyboardEvent, host: CanvasEvent) {
|
|||||||
const enterText: IElement = {
|
const enterText: IElement = {
|
||||||
value: ZERO
|
value: ZERO
|
||||||
}
|
}
|
||||||
// 标题结尾处回车无需格式化
|
const startElement = elementList[startIndex]
|
||||||
const endElement = elementList[endIndex]
|
const endElement = elementList[endIndex]
|
||||||
|
// 列表块内换行
|
||||||
|
if (evt.shiftKey && startElement.listId) {
|
||||||
|
enterText.listWrap = true
|
||||||
|
}
|
||||||
|
// 标题结尾处回车无需格式化
|
||||||
if (!(endElement.titleId && endElement.titleId !== elementList[endIndex + 1]?.titleId)) {
|
if (!(endElement.titleId && endElement.titleId !== elementList[endIndex + 1]?.titleId)) {
|
||||||
formatElementContext(elementList, [enterText], startIndex)
|
formatElementContext(elementList, [enterText], startIndex)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,8 @@ export const EDITOR_ELEMENT_ZIP_ATTR: Array<keyof IElement> = [
|
|||||||
'block',
|
'block',
|
||||||
'level',
|
'level',
|
||||||
'listType',
|
'listType',
|
||||||
'listStyle'
|
'listStyle',
|
||||||
|
'listWrap'
|
||||||
]
|
]
|
||||||
|
|
||||||
export const EDITOR_ELEMENT_CONTEXT_ATTR: Array<keyof IElement> = [
|
export const EDITOR_ELEMENT_CONTEXT_ATTR: Array<keyof IElement> = [
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ export interface IListElement {
|
|||||||
listType?: ListType;
|
listType?: ListType;
|
||||||
listStyle?: ListStyle;
|
listStyle?: ListStyle;
|
||||||
listId?: string;
|
listId?: string;
|
||||||
|
listWrap?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ITableAttr {
|
export interface ITableAttr {
|
||||||
|
|||||||
@@ -110,6 +110,11 @@ export function writeElementList(elementList: IElement[], options: DeepRequired<
|
|||||||
const zipList = zipElementList(element.valueList!)
|
const zipList = zipElementList(element.valueList!)
|
||||||
for (let z = 0; z < zipList.length; z++) {
|
for (let z = 0; z < zipList.length; z++) {
|
||||||
const zipElement = zipList[z]
|
const zipElement = zipList[z]
|
||||||
|
if (zipElement.listWrap) {
|
||||||
|
const listElementList = listElementListMap.get(curListIndex) || []
|
||||||
|
listElementList.push(zipElement)
|
||||||
|
listElementListMap.set(curListIndex, listElementList)
|
||||||
|
} else {
|
||||||
const zipValueList = zipElement.value.split('\n')
|
const zipValueList = zipElement.value.split('\n')
|
||||||
for (let c = 0; c < zipValueList.length; c++) {
|
for (let c = 0; c < zipValueList.length; c++) {
|
||||||
if (c > 0) {
|
if (c > 0) {
|
||||||
@@ -124,6 +129,7 @@ export function writeElementList(elementList: IElement[], options: DeepRequired<
|
|||||||
listElementListMap.set(curListIndex, listElementList)
|
listElementListMap.set(curListIndex, listElementList)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
listElementListMap.forEach(listElementList => {
|
listElementListMap.forEach(listElementList => {
|
||||||
const li = document.createElement('li')
|
const li = document.createElement('li')
|
||||||
const childDom = buildDomFromElementList(listElementList)
|
const childDom = buildDomFromElementList(listElementList)
|
||||||
@@ -264,6 +270,11 @@ export function getElementListByHTML(htmlText: string, options: IGetElementListB
|
|||||||
}
|
}
|
||||||
listNode.querySelectorAll('li').forEach(li => {
|
listNode.querySelectorAll('li').forEach(li => {
|
||||||
const liValueList = getElementListByHTML(li.innerHTML, options)
|
const liValueList = getElementListByHTML(li.innerHTML, options)
|
||||||
|
liValueList.forEach(list => {
|
||||||
|
if (list.value === '\n') {
|
||||||
|
list.listWrap = true
|
||||||
|
}
|
||||||
|
})
|
||||||
liValueList.unshift({
|
liValueList.unshift({
|
||||||
value: '\n'
|
value: '\n'
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user