From b87510558c99db4e5c0fc6d5006b5f3595fa2176 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Tue, 18 Apr 2023 11:06:33 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E5=8F=AA=E8=AF=BB=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E4=B8=8B=E4=B8=8D=E5=87=BA=E7=8E=B0=E7=B2=98=E8=B4=B4=E9=80=89?= =?UTF-8?q?=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/menus/protyle.ts | 120 ++++++++++++++++++++------------------- 1 file changed, 61 insertions(+), 59 deletions(-) diff --git a/app/src/menus/protyle.ts b/app/src/menus/protyle.ts index 308c38494..312a938c8 100644 --- a/app/src/menus/protyle.ts +++ b/app/src/menus/protyle.ts @@ -340,71 +340,73 @@ export const contentMenu = (protyle: IProtyle, nodeElement: Element) => { } }).element); } - window.siyuan.menus.menu.append(new MenuItem({ - label: window.siyuan.languages.paste, - accelerator: "⌘V", - async click() { - if (document.queryCommandSupported("paste")) { - document.execCommand("paste"); - } else { + if (!protyle.disabled) { + window.siyuan.menus.menu.append(new MenuItem({ + label: window.siyuan.languages.paste, + accelerator: "⌘V", + async click() { + if (document.queryCommandSupported("paste")) { + document.execCommand("paste"); + } else { + try { + const clipText = await readText(); + pasteText(protyle, clipText, nodeElement); + } catch (e) { + console.log(e); + } + } + } + }).element); + /// #if !BROWSER + window.siyuan.menus.menu.append(new MenuItem({ + label: window.siyuan.languages.pasteAsPlainText, + accelerator: "⇧⌘V", + click() { + focusByRange(getEditorRange(nodeElement)); + pasteAsPlainText(protyle); + } + }).element); + /// #endif + window.siyuan.menus.menu.append(new MenuItem({ + label: window.siyuan.languages.pasteEscaped, + async click() { try { - const clipText = await readText(); + // * _ [ ] ! \ ` < > & ~ { } ( ) = # $ ^ | + let clipText = await readText(); + // https://github.com/siyuan-note/siyuan/issues/5446 + // A\B\C\D\ + // E + // task-blog-2~default~baiduj 无法原义粘贴含有 `~foo~` 的文本 https://github.com/siyuan-note/siyuan/issues/5523 + + // 这里必须多加一个反斜杆,因为 Lute 在进行 Markdown 嵌套节点转换平铺标记节点时会剔除 Backslash 节点, + // 多加入的一个反斜杆会作为文本节点保留下来,后续 Spin 时刚好用于转义标记符 https://github.com/siyuan-note/siyuan/issues/6341 + clipText = clipText.replace(/\\/g, "\\\\\\\\") + .replace(/\*/g, "\\\\\\*") + .replace(/\_/g, "\\\\\\_") + .replace(/\[/g, "\\\\\\[") + .replace(/\]/g, "\\\\\\]") + .replace(/\!/g, "\\\\\\!") + .replace(/\`/g, "\\\\\\`") + .replace(/\/g, "\\\\\\>") + .replace(/\&/g, "\\\\\\&") + .replace(/\~/g, "\\\\\\~") + .replace(/\{/g, "\\\\\\{") + .replace(/\}/g, "\\\\\\}") + .replace(/\(/g, "\\\\\\(") + .replace(/\)/g, "\\\\\\)") + .replace(/\=/g, "\\\\\\=") + .replace(/\#/g, "\\\\\\#") + .replace(/\$/g, "\\\\\\$") + .replace(/\^/g, "\\\\\\^") + .replace(/\|/g, "\\\\\\|"); pasteText(protyle, clipText, nodeElement); } catch (e) { console.log(e); } } - } - }).element); - /// #if !BROWSER - window.siyuan.menus.menu.append(new MenuItem({ - label: window.siyuan.languages.pasteAsPlainText, - accelerator: "⇧⌘V", - click() { - focusByRange(getEditorRange(nodeElement)); - pasteAsPlainText(protyle); - } - }).element); - /// #endif - window.siyuan.menus.menu.append(new MenuItem({ - label: window.siyuan.languages.pasteEscaped, - async click() { - try { - // * _ [ ] ! \ ` < > & ~ { } ( ) = # $ ^ | - let clipText = await readText(); - // https://github.com/siyuan-note/siyuan/issues/5446 - // A\B\C\D\ - // E - // task-blog-2~default~baiduj 无法原义粘贴含有 `~foo~` 的文本 https://github.com/siyuan-note/siyuan/issues/5523 - - // 这里必须多加一个反斜杆,因为 Lute 在进行 Markdown 嵌套节点转换平铺标记节点时会剔除 Backslash 节点, - // 多加入的一个反斜杆会作为文本节点保留下来,后续 Spin 时刚好用于转义标记符 https://github.com/siyuan-note/siyuan/issues/6341 - clipText = clipText.replace(/\\/g, "\\\\\\\\") - .replace(/\*/g, "\\\\\\*") - .replace(/\_/g, "\\\\\\_") - .replace(/\[/g, "\\\\\\[") - .replace(/\]/g, "\\\\\\]") - .replace(/\!/g, "\\\\\\!") - .replace(/\`/g, "\\\\\\`") - .replace(/\/g, "\\\\\\>") - .replace(/\&/g, "\\\\\\&") - .replace(/\~/g, "\\\\\\~") - .replace(/\{/g, "\\\\\\{") - .replace(/\}/g, "\\\\\\}") - .replace(/\(/g, "\\\\\\(") - .replace(/\)/g, "\\\\\\)") - .replace(/\=/g, "\\\\\\=") - .replace(/\#/g, "\\\\\\#") - .replace(/\$/g, "\\\\\\$") - .replace(/\^/g, "\\\\\\^") - .replace(/\|/g, "\\\\\\|"); - pasteText(protyle, clipText, nodeElement); - } catch (e) { - console.log(e); - } - } - }).element); + }).element); + } window.siyuan.menus.menu.append(new MenuItem({ label: window.siyuan.languages.selectAll, accelerator: "⌘A",