From d9f7441170ab068d4e57ff195c9fcffbd84d1359 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Wed, 31 Jan 2024 11:02:32 +0800 Subject: [PATCH] :art: fix https://github.com/siyuan-note/siyuan/issues/10282 --- app/src/protyle/render/av/cell.ts | 4 ++-- app/src/protyle/util/paste.ts | 15 ++++++++++++++- app/src/protyle/wysiwyg/index.ts | 6 +++--- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/app/src/protyle/render/av/cell.ts b/app/src/protyle/render/av/cell.ts index 212ae968e..6cce73002 100644 --- a/app/src/protyle/render/av/cell.ts +++ b/app/src/protyle/render/av/cell.ts @@ -467,7 +467,7 @@ export const updateCellsValue = (protyle: IProtyle, nodeElement: HTMLElement, va const cellId = item.getAttribute("data-id"); const colId = item.getAttribute("data-col-id"); - text += getCellText(item) + " "; + text += getCellText(item) + ((cellElements[elementIndex + 1] && item.nextElementSibling && item.nextElementSibling.isSameNode(cellElements[elementIndex + 1])) ? "\t" : "\n\n"); const oldValue = genCellValueByElement(type, item); json.push(oldValue); // relation 为全部更新,以下类型为添加 @@ -531,7 +531,7 @@ export const updateCellsValue = (protyle: IProtyle, nodeElement: HTMLElement, va }); transaction(protyle, doOperations, undoOperations); } - return {text: text.substring(0, text.length - 1), json}; + return {text: text.substring(0, text.length - 2), json}; }; export const renderCellAttr = (cellElement: Element, value: IAVCellValue) => { diff --git a/app/src/protyle/util/paste.ts b/app/src/protyle/util/paste.ts index 0e56fc04c..e2ed3b97a 100644 --- a/app/src/protyle/util/paste.ts +++ b/app/src/protyle/util/paste.ts @@ -271,7 +271,20 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEven e.setAttribute("contenteditable", "true"); }); const tempInnerHTML = tempElement.innerHTML; - insertHTML(tempInnerHTML, protyle, isBlock); + if (!nodeElement.classList.contains("av") && tempInnerHTML.startsWith("[{") && tempInnerHTML.endsWith("}]")) { + try { + const json = JSON.parse(tempInnerHTML); + if (json.length > 0 && json[0].id && json[0].type) { + insertHTML(textPlain, protyle, isBlock); + } else { + insertHTML(tempInnerHTML, protyle, isBlock); + } + } catch (e) { + insertHTML(tempInnerHTML, protyle, isBlock); + } + } else { + insertHTML(tempInnerHTML, protyle, isBlock); + } filterClipboardHint(protyle, protyle.lute.BlockDOM2StdMd(tempInnerHTML)); blockRender(protyle, protyle.wysiwyg.element); processRender(protyle.wysiwyg.element); diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts index 0531dca70..523c633cd 100644 --- a/app/src/protyle/wysiwyg/index.ts +++ b/app/src/protyle/wysiwyg/index.ts @@ -304,12 +304,12 @@ export class WYSIWYG { } if (cellElements.length > 0) { html = "["; - cellElements.forEach((item: HTMLElement) => { + cellElements.forEach((item: HTMLElement, index) => { const cellText = getCellText(item); html += JSON.stringify(genCellValueByElement(getTypeByCellElement(item), item)) + ","; - textPlain += cellText + " "; + textPlain += cellText + ((cellElements[index + 1] && item.nextElementSibling && item.nextElementSibling.isSameNode(cellElements[index + 1])) ? "\t" : "\n\n"); }); - textPlain = textPlain.substring(0, textPlain.length - 1); + textPlain = textPlain.substring(0, textPlain.length - 2); html = html.substring(0, html.length - 1) + "]"; } } else {