Explorar el Código

:art: fix https://github.com/siyuan-note/siyuan/issues/6489

Vanessa hace 2 años
padre
commit
696953a79e

+ 1 - 1
app/src/config/keymap.ts

@@ -278,7 +278,7 @@ export const keymap = {
                     }
                     }
 
 
                     if (["⌘", "⇧", "⌥", "⌃"].includes(keymapStr.substr(keymapStr.length - 1, 1)) ||
                     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);
                         showMessage(tip + "] " + window.siyuan.languages.invalid);
                         return;
                         return;
                     }
                     }

+ 1 - 2
app/src/constants.ts

@@ -105,7 +105,7 @@ export abstract class Constants {
         "222": ["'", '"'],
         "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 = {
     public static readonly SIYUAN_KEYMAP: IKeymap = {
         general: {
         general: {
             syncNow: {default: "F9", custom: "F9"},
             syncNow: {default: "F9", custom: "F9"},
@@ -157,7 +157,6 @@ export abstract class Constants {
                 copyProtocol: {default: "⇧⌘H", custom: "⇧⌘H"},
                 copyProtocol: {default: "⇧⌘H", custom: "⇧⌘H"},
                 copyBlockEmbed: {default: "⇧⌘E", custom: "⇧⌘E"},
                 copyBlockEmbed: {default: "⇧⌘E", custom: "⇧⌘E"},
                 copyHPath: {default: "⇧⌘P", custom: "⇧⌘P"},
                 copyHPath: {default: "⇧⌘P", custom: "⇧⌘P"},
-                pasteAsPlainText: {default: "⇧⌘V", custom: "⇧⌘V"},
                 undo: {default: "⌘Z", custom: "⌘Z"},
                 undo: {default: "⌘Z", custom: "⌘Z"},
                 redo: {default: "⌘Y", custom: "⌘Y"},
                 redo: {default: "⌘Y", custom: "⌘Y"},
                 rename: {default: "F2", custom: "F2"},
                 rename: {default: "F2", custom: "F2"},

+ 6 - 3
app/src/menus/protyle.ts

@@ -23,10 +23,13 @@ import {readText, writeText} from "../protyle/util/compatibility";
 import {preventScroll} from "../protyle/scroll/preventScroll";
 import {preventScroll} from "../protyle/scroll/preventScroll";
 import {onGet} from "../protyle/util/onGet";
 import {onGet} from "../protyle/util/onGet";
 import {getAllModels} from "../layout/getAll";
 import {getAllModels} from "../layout/getAll";
-import {pasteAsPlainText, pasteText} from "../protyle/util/paste";
+import {pasteText} from "../protyle/util/paste";
 /// #if !MOBILE
 /// #if !MOBILE
 import {openFileById, updateBacklinkGraph} from "../editor/util";
 import {openFileById, updateBacklinkGraph} from "../editor/util";
 /// #endif
 /// #endif
+/// #if !BROWSER
+import {getCurrentWindow} from "@electron/remote";
+/// #endif
 import {isMobile} from "../util/functions";
 import {isMobile} from "../util/functions";
 import {removeFoldHeading} from "../protyle/util/heading";
 import {removeFoldHeading} from "../protyle/util/heading";
 import {lineNumberRender} from "../protyle/markdown/highlightRender";
 import {lineNumberRender} from "../protyle/markdown/highlightRender";
@@ -358,10 +361,10 @@ export const contentMenu = (protyle: IProtyle, nodeElement: Element) => {
     /// #if !BROWSER && !MOBILE
     /// #if !BROWSER && !MOBILE
     window.siyuan.menus.menu.append(new MenuItem({
     window.siyuan.menus.menu.append(new MenuItem({
         label: window.siyuan.languages.pasteAsPlainText,
         label: window.siyuan.languages.pasteAsPlainText,
-        accelerator: window.siyuan.config.keymap.editor.general.pasteAsPlainText.custom,
+        accelerator: "⇧⌘V",
         click() {
         click() {
             focusByRange(getEditorRange(nodeElement));
             focusByRange(getEditorRange(nodeElement));
-            pasteAsPlainText(protyle);
+            getCurrentWindow().webContents.pasteAndMatchStyle();
         }
         }
     }).element);
     }).element);
     /// #endif
     /// #endif

+ 0 - 28
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) => {
 export const pasteText = (protyle: IProtyle, textPlain: string, nodeElement: Element) => {
     const range = getEditorRange(protyle.wysiwyg.element);
     const range = getEditorRange(protyle.wysiwyg.element);
     if (nodeElement.getAttribute("data-type") === "NodeCodeBlock") {
     if (nodeElement.getAttribute("data-type") === "NodeCodeBlock") {

+ 5 - 3
app/src/protyle/wysiwyg/keydown.ts

@@ -42,6 +42,9 @@ import {isLocalPath} from "../../util/pathName";
 /// #if !MOBILE
 /// #if !MOBILE
 import {openBy, openFileById} from "../../editor/util";
 import {openBy, openFileById} from "../../editor/util";
 /// #endif
 /// #endif
+/// #if !BROWSER
+import {getCurrentWindow} from "@electron/remote";
+/// #endif
 import {commonHotkey, downSelect, getStartEndElement, upSelect} from "./commonHotkey";
 import {commonHotkey, downSelect, getStartEndElement, upSelect} from "./commonHotkey";
 import {linkMenu, refMenu, setFold, zoomOut} from "../../menus/protyle";
 import {linkMenu, refMenu, setFold, zoomOut} from "../../menus/protyle";
 import {removeEmbed} from "./removeEmbed";
 import {removeEmbed} from "./removeEmbed";
@@ -56,7 +59,6 @@ import * as dayjs from "dayjs";
 import {highlightRender} from "../markdown/highlightRender";
 import {highlightRender} from "../markdown/highlightRender";
 import {countBlockWord} from "../../layout/status";
 import {countBlockWord} from "../../layout/status";
 import {openMobileFileById} from "../../mobile/editor";
 import {openMobileFileById} from "../../mobile/editor";
-import {pasteAsPlainText} from "../util/paste";
 import {moveToDown, moveToUp} from "./move";
 import {moveToDown, moveToUp} from "./move";
 
 
 export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
 export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
@@ -1577,11 +1579,11 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
         /// #endif
         /// #endif
 
 
         /// #if !BROWSER && !MOBILE
         /// #if !BROWSER && !MOBILE
-        if (matchHotKey(window.siyuan.config.keymap.editor.general.pasteAsPlainText.custom, event)) {
+        if (matchHotKey("⇧⌘V", event)) {
             event.returnValue = false;
             event.returnValue = false;
             event.preventDefault();
             event.preventDefault();
             event.stopPropagation();
             event.stopPropagation();
-            pasteAsPlainText(protyle);
+            getCurrentWindow().webContents.pasteAndMatchStyle();
             return;
             return;
         }
         }
 
 

+ 0 - 4
app/src/types/protyle.d.ts

@@ -147,8 +147,6 @@ declare class Lute {
 
 
     public BlockDOM2Content(text: string): string;
     public BlockDOM2Content(text: string): string;
 
 
-    public InlineMd2BlockDOM(text: string): string;
-
     public SetTextMark(enable: boolean): void;
     public SetTextMark(enable: boolean): void;
 
 
     public SetHeadingID(enable: boolean): void;
     public SetHeadingID(enable: boolean): void;
@@ -215,8 +213,6 @@ declare class Lute {
 
 
     public SetProtyleWYSIWYG(wysiwyg: boolean): void;
     public SetProtyleWYSIWYG(wysiwyg: boolean): void;
 
 
-    public SetHTMLTag2TextMark(enable: boolean): void;
-
     public MarkdownStr(name: string, md: string): string;
     public MarkdownStr(name: string, md: string): string;
 
 
     public IsValidLinkDest(text: string): boolean;
     public IsValidLinkDest(text: string): boolean;