mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-20 16:40:13 +01:00
This commit is contained in:
parent
660affc487
commit
5fdfa40551
2 changed files with 21 additions and 27 deletions
|
|
@ -6,6 +6,8 @@ import {getContenteditableElement} from "../wysiwyg/getBlock";
|
||||||
import {focusBlock, getEditorRange, focusByWbr, fixTableRange} from "./selection";
|
import {focusBlock, getEditorRange, focusByWbr, fixTableRange} from "./selection";
|
||||||
import {mathRender} from "../markdown/mathRender";
|
import {mathRender} from "../markdown/mathRender";
|
||||||
import {Constants} from "../../constants";
|
import {Constants} from "../../constants";
|
||||||
|
import {highlightRender} from "../markdown/highlightRender";
|
||||||
|
import {scrollCenter} from "../../util/highlightById";
|
||||||
|
|
||||||
export const insertHTML = (html: string, protyle: IProtyle, isBlock = false) => {
|
export const insertHTML = (html: string, protyle: IProtyle, isBlock = false) => {
|
||||||
if (html === "") {
|
if (html === "") {
|
||||||
|
|
@ -31,6 +33,21 @@ export const insertHTML = (html: string, protyle: IProtyle, isBlock = false) =>
|
||||||
let id = blockElement.getAttribute("data-node-id");
|
let id = blockElement.getAttribute("data-node-id");
|
||||||
range.insertNode(document.createElement("wbr"));
|
range.insertNode(document.createElement("wbr"));
|
||||||
let oldHTML = blockElement.outerHTML;
|
let oldHTML = blockElement.outerHTML;
|
||||||
|
if (!isBlock && blockElement.getAttribute("data-type") === "NodeCodeBlock") {
|
||||||
|
range.deleteContents();
|
||||||
|
range.insertNode(document.createTextNode(html.replace(/\r\n|\r|\u2028|\u2029/g, "\n")));
|
||||||
|
range.collapse(false);
|
||||||
|
range.insertNode(document.createElement("wbr"));
|
||||||
|
getContenteditableElement(blockElement).removeAttribute("data-render");
|
||||||
|
highlightRender(blockElement);
|
||||||
|
blockElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));
|
||||||
|
updateTransaction(protyle, id, blockElement.outerHTML, oldHTML);
|
||||||
|
setTimeout(() => {
|
||||||
|
scrollCenter(protyle, blockElement);
|
||||||
|
}, Constants.TIMEOUT_BLOCKLOAD);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const undoOperation: IOperation[] = [];
|
const undoOperation: IOperation[] = [];
|
||||||
const doOperation: IOperation[] = [];
|
const doOperation: IOperation[] = [];
|
||||||
if (range.toString() !== "") {
|
if (range.toString() !== "") {
|
||||||
|
|
|
||||||
|
|
@ -54,27 +54,16 @@ export const pasteAsPlainText = async (protyle:IProtyle) => {
|
||||||
protyle.lute.SetHTMLTag2TextMark(true); // 临时设置 Lute 解析参数,行级元素键盘和下划线无法粘贴为纯文本 https://github.com/siyuan-note/siyuan/issues/6220
|
protyle.lute.SetHTMLTag2TextMark(true); // 临时设置 Lute 解析参数,行级元素键盘和下划线无法粘贴为纯文本 https://github.com/siyuan-note/siyuan/issues/6220
|
||||||
const dom = protyle.lute.InlineMd2BlockDOM(clipboard.readText());
|
const dom = protyle.lute.InlineMd2BlockDOM(clipboard.readText());
|
||||||
protyle.lute.SetHTMLTag2TextMark(false);
|
protyle.lute.SetHTMLTag2TextMark(false);
|
||||||
insertHTML(protyle.lute.BlockDOM2Content(dom), protyle, false);
|
insertHTML(protyle.lute.BlockDOM2Content(dom), protyle);
|
||||||
}
|
}
|
||||||
/// #endif
|
/// #endif
|
||||||
};
|
};
|
||||||
|
|
||||||
export const pasteText = (protyle: IProtyle, textPlain: string, nodeElement: Element) => {
|
export const pasteText = (protyle: IProtyle, textPlain: string, nodeElement: Element) => {
|
||||||
const range = getEditorRange(protyle.wysiwyg.element);
|
const range = getEditorRange(protyle.wysiwyg.element);
|
||||||
const id = nodeElement.getAttribute("data-node-id");
|
|
||||||
if (nodeElement.getAttribute("data-type") === "NodeCodeBlock") {
|
if (nodeElement.getAttribute("data-type") === "NodeCodeBlock") {
|
||||||
// 粘贴在代码位置
|
// 粘贴在代码位置
|
||||||
range.insertNode(document.createElement("wbr"));
|
insertHTML(textPlain, protyle);
|
||||||
const html = nodeElement.outerHTML;
|
|
||||||
range.deleteContents();
|
|
||||||
range.insertNode(document.createTextNode(textPlain.replace(/\r\n|\r|\u2028|\u2029/g, "\n")));
|
|
||||||
range.collapse(false);
|
|
||||||
range.insertNode(document.createElement("wbr"));
|
|
||||||
nodeElement.outerHTML = protyle.lute.SpinBlockDOM(nodeElement.outerHTML);
|
|
||||||
nodeElement = protyle.wysiwyg.element.querySelector(`[data-node-id="${id}"]`) as HTMLElement;
|
|
||||||
highlightRender(nodeElement);
|
|
||||||
nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));
|
|
||||||
updateTransaction(protyle, id, nodeElement.outerHTML, html);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (range.toString() !== "") {
|
if (range.toString() !== "") {
|
||||||
|
|
@ -184,19 +173,7 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEven
|
||||||
// process code
|
// process code
|
||||||
if (nodeElement.getAttribute("data-type") === "NodeCodeBlock") {
|
if (nodeElement.getAttribute("data-type") === "NodeCodeBlock") {
|
||||||
// 粘贴在代码位置
|
// 粘贴在代码位置
|
||||||
range.insertNode(document.createElement("wbr"));
|
insertHTML(textPlain, protyle);
|
||||||
const html = nodeElement.outerHTML;
|
|
||||||
range.deleteContents();
|
|
||||||
range.insertNode(document.createTextNode(textPlain.replace(/\r\n|\r|\u2028|\u2029/g, "\n")));
|
|
||||||
range.collapse(false);
|
|
||||||
range.insertNode(document.createElement("wbr"));
|
|
||||||
getContenteditableElement(nodeElement).removeAttribute("data-render");
|
|
||||||
highlightRender(nodeElement);
|
|
||||||
nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));
|
|
||||||
updateTransaction(protyle, id, nodeElement.outerHTML, html);
|
|
||||||
setTimeout(() => {
|
|
||||||
scrollCenter(protyle, nodeElement as Element);
|
|
||||||
}, Constants.TIMEOUT_BLOCKLOAD);
|
|
||||||
return;
|
return;
|
||||||
} else if (code) {
|
} else if (code) {
|
||||||
if (!code.startsWith('<div data-type="NodeCodeBlock" class="code-block" data-node-id="')) {
|
if (!code.startsWith('<div data-type="NodeCodeBlock" class="code-block" data-node-id="')) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue