feat: optimize paste title
This commit is contained in:
@@ -84,6 +84,7 @@ export class CursorAgent {
|
|||||||
let start = 0
|
let start = 0
|
||||||
while (start < pasteElementList.length) {
|
while (start < pasteElementList.length) {
|
||||||
const pasteElement = pasteElementList[start]
|
const pasteElement = pasteElementList[start]
|
||||||
|
if (anchorElement.titleId && /^\n/.test(pasteElement.value)) break
|
||||||
if (VIRTUAL_ELEMENT_TYPE.includes(pasteElement.type!)) {
|
if (VIRTUAL_ELEMENT_TYPE.includes(pasteElement.type!)) {
|
||||||
pasteElementList.splice(start, 1)
|
pasteElementList.splice(start, 1)
|
||||||
if (pasteElement.valueList) {
|
if (pasteElement.valueList) {
|
||||||
@@ -99,7 +100,9 @@ export class CursorAgent {
|
|||||||
start++
|
start++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
formatElementContext(elementList, pasteElementList, startIndex)
|
formatElementContext(elementList, pasteElementList, startIndex, {
|
||||||
|
isBreakWhenWrap: true
|
||||||
|
})
|
||||||
}
|
}
|
||||||
this.draw.insertElementList(pasteElementList)
|
this.draw.insertElementList(pasteElementList)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -563,11 +563,17 @@ export function getAnchorElement(elementList: IElement[], anchorIndex: number):
|
|||||||
: anchorElement
|
: 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)
|
const copyElement = getAnchorElement(sourceElementList, anchorIndex)
|
||||||
if (!copyElement) return
|
if (!copyElement) return
|
||||||
|
const { isBreakWhenWrap = false } = options || {}
|
||||||
for (let e = 0; e < formatElementList.length; e++) {
|
for (let e = 0; e < formatElementList.length; e++) {
|
||||||
const targetElement = formatElementList[e]
|
const targetElement = formatElementList[e]
|
||||||
|
if (isBreakWhenWrap && !copyElement.listId && /^\n/.test(targetElement.value)) break
|
||||||
// 定位元素非列表,无需处理粘贴列表的上下文
|
// 定位元素非列表,无需处理粘贴列表的上下文
|
||||||
if (!copyElement.listId && targetElement.type === ElementType.LIST) continue
|
if (!copyElement.listId && targetElement.type === ElementType.LIST) continue
|
||||||
if (targetElement.valueList && targetElement.valueList.length) {
|
if (targetElement.valueList && targetElement.valueList.length) {
|
||||||
|
|||||||
Reference in New Issue
Block a user