diff --git a/app/src/config/keymap.ts b/app/src/config/keymap.ts index fef38544e..7e24d409c 100644 --- a/app/src/config/keymap.ts +++ b/app/src/config/keymap.ts @@ -278,7 +278,7 @@ export const keymap = { } if (["⌘", "⇧", "⌥", "⌃"].includes(keymapStr.substr(keymapStr.length - 1, 1)) || - ["⌘A", "⌘X", "⌘C", "⌘V", "⌘/", "⇧↑", "⇧↓", "⇧→", "⇧←", "⇧⇥", "⇧⌘⇥", "⌃⇥", "⌘⇥", "⌃⌘⇥", "⇧⌘→", "⇧⌘←", "⌘Home", "⌘End", "⇧↩", "↩", "PageUp", "PageDown", "⌫", "⌦"].includes(keymapStr)) { + ["⌘A", "⌘X", "⌘C", "⌘V", "⇧⌘V", "⌘/", "⇧↑", "⇧↓", "⇧→", "⇧←", "⇧⇥", "⇧⌘⇥", "⌃⇥", "⌘⇥", "⌃⌘⇥", "⇧⌘→", "⇧⌘←", "⌘Home", "⌘End", "⇧↩", "↩", "PageUp", "PageDown", "⌫", "⌦"].includes(keymapStr)) { showMessage(tip + "] " + window.siyuan.languages.invalid); return; } diff --git a/app/src/constants.ts b/app/src/constants.ts index 7794fed20..296aea230 100644 --- a/app/src/constants.ts +++ b/app/src/constants.ts @@ -105,7 +105,7 @@ export abstract class Constants { "222": ["'", '"'], }; // "⌘", "⇧", "⌥", "⌃" - // "⌘A", "⌘X", "⌘C", "⌘V", "⌘/", "⇧↑", "⇧↓", "⇧→", "⇧←", "⇧⇥", "⇧⌘⇥", "⌃⇥", "⌘⇥", "⌃⌘⇥", "⇧⌘→", "⇧⌘←", "⌘Home", "⌘End", "⇧↩", "↩", "PageUp", "PageDown", "⌫", "⌦", "⌃I", "⌃E", "⌃N", "⌃U" 不可自定义 + // "⌘A", "⌘X", "⌘C", "⌘V", "⇧⌘V", "⌘/", "⇧↑", "⇧↓", "⇧→", "⇧←", "⇧⇥", "⇧⌘⇥", "⌃⇥", "⌘⇥", "⌃⌘⇥", "⇧⌘→", "⇧⌘←", "⌘Home", "⌘End", "⇧↩", "↩", "PageUp", "PageDown", "⌫", "⌦" 不可自定义 public static readonly SIYUAN_KEYMAP: IKeymap = { general: { syncNow: {default: "F9", custom: "F9"}, @@ -157,7 +157,6 @@ export abstract class Constants { copyProtocol: {default: "⇧⌘H", custom: "⇧⌘H"}, copyBlockEmbed: {default: "⇧⌘E", custom: "⇧⌘E"}, copyHPath: {default: "⇧⌘P", custom: "⇧⌘P"}, - pasteAsPlainText: {default: "⇧⌘V", custom: "⇧⌘V"}, undo: {default: "⌘Z", custom: "⌘Z"}, redo: {default: "⌘Y", custom: "⌘Y"}, rename: {default: "F2", custom: "F2"}, diff --git a/app/src/menus/protyle.ts b/app/src/menus/protyle.ts index 741ce4f9d..557ce80ba 100644 --- a/app/src/menus/protyle.ts +++ b/app/src/menus/protyle.ts @@ -23,10 +23,13 @@ import {readText, writeText} from "../protyle/util/compatibility"; import {preventScroll} from "../protyle/scroll/preventScroll"; import {onGet} from "../protyle/util/onGet"; import {getAllModels} from "../layout/getAll"; -import {pasteAsPlainText, pasteText} from "../protyle/util/paste"; +import {pasteText} from "../protyle/util/paste"; /// #if !MOBILE import {openFileById, updateBacklinkGraph} from "../editor/util"; /// #endif +/// #if !BROWSER +import {getCurrentWindow} from "@electron/remote"; +/// #endif import {isMobile} from "../util/functions"; import {removeFoldHeading} from "../protyle/util/heading"; import {lineNumberRender} from "../protyle/markdown/highlightRender"; @@ -358,10 +361,10 @@ export const contentMenu = (protyle: IProtyle, nodeElement: Element) => { /// #if !BROWSER && !MOBILE window.siyuan.menus.menu.append(new MenuItem({ label: window.siyuan.languages.pasteAsPlainText, - accelerator: window.siyuan.config.keymap.editor.general.pasteAsPlainText.custom, + accelerator: "⇧⌘V", click() { focusByRange(getEditorRange(nodeElement)); - pasteAsPlainText(protyle); + getCurrentWindow().webContents.pasteAndMatchStyle(); } }).element); /// #endif diff --git a/app/src/protyle/util/paste.ts b/app/src/protyle/util/paste.ts index 628ea707e..d853def84 100644 --- a/app/src/protyle/util/paste.ts +++ b/app/src/protyle/util/paste.ts @@ -29,34 +29,6 @@ const filterClipboardHint = (protyle: IProtyle, textPlain: string) => { } }; -export const pasteAsPlainText = async (protyle: IProtyle) => { - /// #if !BROWSER && !MOBILE - let localFiles: string[] = []; - if ("darwin" === window.siyuan.config.system.os) { - const xmlString = clipboard.read("NSFilenamesPboardType"); - const domParser = new DOMParser(); - const xmlDom = domParser.parseFromString(xmlString, "application/xml"); - Array.from(xmlDom.getElementsByTagName("string")).forEach(item => { - localFiles.push(item.childNodes[0].nodeValue); - }); - } else { - const xmlString = await fetchSyncPost("/api/clipboard/readFilePaths", {}); - if (xmlString.data.length > 0) { - localFiles = xmlString.data; - } - } - if (localFiles.length > 0) { - uploadLocalFiles(localFiles, protyle, false); - writeText(""); - } else { - protyle.lute.SetHTMLTag2TextMark(true); // 临时设置 Lute 解析参数,行级元素键盘和下划线无法粘贴为纯文本 https://github.com/siyuan-note/siyuan/issues/6220 - const dom = protyle.lute.InlineMd2BlockDOM(clipboard.readText()); - protyle.lute.SetHTMLTag2TextMark(false); - insertHTML(protyle.lute.BlockDOM2Content(dom), protyle); - } - /// #endif -}; - export const pasteText = (protyle: IProtyle, textPlain: string, nodeElement: Element) => { const range = getEditorRange(protyle.wysiwyg.element); if (nodeElement.getAttribute("data-type") === "NodeCodeBlock") { diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts index 7348a9570..8bf7e78f7 100644 --- a/app/src/protyle/wysiwyg/keydown.ts +++ b/app/src/protyle/wysiwyg/keydown.ts @@ -42,6 +42,9 @@ import {isLocalPath} from "../../util/pathName"; /// #if !MOBILE import {openBy, openFileById} from "../../editor/util"; /// #endif +/// #if !BROWSER +import {getCurrentWindow} from "@electron/remote"; +/// #endif import {commonHotkey, downSelect, getStartEndElement, upSelect} from "./commonHotkey"; import {linkMenu, refMenu, setFold, zoomOut} from "../../menus/protyle"; import {removeEmbed} from "./removeEmbed"; @@ -56,7 +59,6 @@ import * as dayjs from "dayjs"; import {highlightRender} from "../markdown/highlightRender"; import {countBlockWord} from "../../layout/status"; import {openMobileFileById} from "../../mobile/editor"; -import {pasteAsPlainText} from "../util/paste"; import {moveToDown, moveToUp} from "./move"; export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { @@ -1577,11 +1579,11 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { /// #endif /// #if !BROWSER && !MOBILE - if (matchHotKey(window.siyuan.config.keymap.editor.general.pasteAsPlainText.custom, event)) { + if (matchHotKey("⇧⌘V", event)) { event.returnValue = false; event.preventDefault(); event.stopPropagation(); - pasteAsPlainText(protyle); + getCurrentWindow().webContents.pasteAndMatchStyle(); return; } diff --git a/app/src/types/protyle.d.ts b/app/src/types/protyle.d.ts index f4aa67a6a..8f8dff83c 100644 --- a/app/src/types/protyle.d.ts +++ b/app/src/types/protyle.d.ts @@ -147,8 +147,6 @@ declare class Lute { public BlockDOM2Content(text: string): string; - public InlineMd2BlockDOM(text: string): string; - public SetTextMark(enable: boolean): void; public SetHeadingID(enable: boolean): void; @@ -215,8 +213,6 @@ declare class Lute { public SetProtyleWYSIWYG(wysiwyg: boolean): void; - public SetHTMLTag2TextMark(enable: boolean): void; - public MarkdownStr(name: string, md: string): string; public IsValidLinkDest(text: string): boolean;