mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-17 17:40:42 +08:00
This commit is contained in:
parent
fe63530325
commit
bffa2235c2
@ -128,7 +128,28 @@ ${unicode2Emoji(emoji.unicode, true)}</button>`;
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
protyle.toolbar.range = getSelection().getRangeAt(0);
|
protyle.toolbar.range = getSelection().getRangeAt(0);
|
||||||
const start = getSelectionOffset(protyle.toolbar.range.startContainer as HTMLElement, protyle.wysiwyg.element).start;
|
// 粘贴后 range.startContainer 为空 https://github.com/siyuan-note/siyuan/issues/7360
|
||||||
|
if (protyle.toolbar.range.startContainer.nodeType === 3 && protyle.toolbar.range.startContainer.textContent === "") {
|
||||||
|
const lastSibling = hasPreviousSibling(protyle.toolbar.range.startContainer) as Text;
|
||||||
|
if (lastSibling && lastSibling.nodeType === 3) {
|
||||||
|
if (lastSibling.wholeText !== lastSibling.textContent) {
|
||||||
|
let previousSibling = lastSibling.previousSibling;
|
||||||
|
while (previousSibling && previousSibling.nodeType === 3) {
|
||||||
|
if (previousSibling.textContent === "") {
|
||||||
|
previousSibling = previousSibling.previousSibling;
|
||||||
|
previousSibling.nextSibling.remove();
|
||||||
|
} else {
|
||||||
|
lastSibling.textContent = previousSibling.textContent + lastSibling.textContent;
|
||||||
|
previousSibling.remove();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protyle.toolbar.range.setStart(lastSibling, lastSibling.textContent.length);
|
||||||
|
protyle.toolbar.range.collapse(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const start = getSelectionOffset(protyle.toolbar.range.startContainer, protyle.wysiwyg.element).start;
|
||||||
const currentLineValue = protyle.toolbar.range.startContainer.textContent.substring(0, start) || "";
|
const currentLineValue = protyle.toolbar.range.startContainer.textContent.substring(0, start) || "";
|
||||||
const key = this.getKey(currentLineValue, protyle.options.hint.extend);
|
const key = this.getKey(currentLineValue, protyle.options.hint.extend);
|
||||||
if (typeof key === "undefined" ||
|
if (typeof key === "undefined" ||
|
||||||
|
@ -191,7 +191,7 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEven
|
|||||||
});
|
});
|
||||||
const tempInnerHTML = tempElement.innerHTML;
|
const tempInnerHTML = tempElement.innerHTML;
|
||||||
insertHTML(tempInnerHTML, protyle, isBlock);
|
insertHTML(tempInnerHTML, protyle, isBlock);
|
||||||
filterClipboardHint(protyle, tempInnerHTML);
|
filterClipboardHint(protyle, protyle.lute.BlockDOM2StdMd(tempInnerHTML));
|
||||||
blockRender(protyle, protyle.wysiwyg.element);
|
blockRender(protyle, protyle.wysiwyg.element);
|
||||||
processRender(protyle.wysiwyg.element);
|
processRender(protyle.wysiwyg.element);
|
||||||
highlightRender(protyle.wysiwyg.element);
|
highlightRender(protyle.wysiwyg.element);
|
||||||
@ -220,6 +220,7 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEven
|
|||||||
insertHTML(code, protyle, true);
|
insertHTML(code, protyle, true);
|
||||||
highlightRender(protyle.wysiwyg.element);
|
highlightRender(protyle.wysiwyg.element);
|
||||||
}
|
}
|
||||||
|
hideElements(["hint"], protyle)
|
||||||
} else {
|
} else {
|
||||||
let isHTML = false;
|
let isHTML = false;
|
||||||
if (textHTML.replace("<!--StartFragment--><!--EndFragment-->", "").trim() !== "") {
|
if (textHTML.replace("<!--StartFragment--><!--EndFragment-->", "").trim() !== "") {
|
||||||
@ -278,7 +279,7 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEven
|
|||||||
}
|
}
|
||||||
const textPlainDom = protyle.lute.Md2BlockDOM(textPlain);
|
const textPlainDom = protyle.lute.Md2BlockDOM(textPlain);
|
||||||
insertHTML(textPlainDom, protyle);
|
insertHTML(textPlainDom, protyle);
|
||||||
filterClipboardHint(protyle, textPlainDom);
|
filterClipboardHint(protyle, textPlain);
|
||||||
}
|
}
|
||||||
blockRender(protyle, protyle.wysiwyg.element);
|
blockRender(protyle, protyle.wysiwyg.element);
|
||||||
processRender(protyle.wysiwyg.element);
|
processRender(protyle.wysiwyg.element);
|
||||||
|
@ -219,7 +219,7 @@ export const getSelectionPosition = (nodeElement: Element, range?: Range) => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getSelectionOffset = (selectElement: Element, editorElement?: Element, range?: Range) => {
|
export const getSelectionOffset = (selectElement: Node, editorElement?: Element, range?: Range) => {
|
||||||
const position = {
|
const position = {
|
||||||
end: 0,
|
end: 0,
|
||||||
start: 0,
|
start: 0,
|
||||||
|
Loading…
Reference in New Issue
Block a user