Skip to content

Commit

Permalink
feat: optimize paste title
Browse files Browse the repository at this point in the history
  • Loading branch information
Hufe921 committed May 31, 2023
1 parent c97c6ef commit bf52e25
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/editor/core/cursor/CursorAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export class CursorAgent {
let start = 0
while (start < pasteElementList.length) {
const pasteElement = pasteElementList[start]
if (anchorElement.titleId && /^\n/.test(pasteElement.value)) break
if (VIRTUAL_ELEMENT_TYPE.includes(pasteElement.type!)) {
pasteElementList.splice(start, 1)
if (pasteElement.valueList) {
Expand All @@ -99,7 +100,9 @@ export class CursorAgent {
start++
}
}
formatElementContext(elementList, pasteElementList, startIndex)
formatElementContext(elementList, pasteElementList, startIndex, {
isBreakWhenWrap: true
})
}
this.draw.insertElementList(pasteElementList)
})
Expand Down
8 changes: 7 additions & 1 deletion src/editor/utils/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -563,11 +563,17 @@ export function getAnchorElement(elementList: IElement[], anchorIndex: number):
: anchorElement
}

export function formatElementContext(sourceElementList: IElement[], formatElementList: IElement[], anchorIndex: number) {
export interface IFormatElementContextOption {
isBreakWhenWrap: boolean;
}

export function formatElementContext(sourceElementList: IElement[], formatElementList: IElement[], anchorIndex: number, options?: IFormatElementContextOption) {
const copyElement = getAnchorElement(sourceElementList, anchorIndex)
if (!copyElement) return
const { isBreakWhenWrap = false } = options || {}
for (let e = 0; e < formatElementList.length; e++) {
const targetElement = formatElementList[e]
if (isBreakWhenWrap && !copyElement.listId && /^\n/.test(targetElement.value)) break
// 定位元素非列表,无需处理粘贴列表的上下文
if (!copyElement.listId && targetElement.type === ElementType.LIST) continue
if (targetElement.valueList && targetElement.valueList.length) {
Expand Down

0 comments on commit bf52e25

Please sign in to comment.