Преглед изворни кода

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

Vanessa пре 2 година
родитељ
комит
f30e9893e8

+ 2 - 27
app/src/protyle/header/Title.ts

@@ -37,6 +37,7 @@ import {openCardByData} from "../../card/openCard";
 import {makeCard, quickMakeCard} from "../../card/makeCard";
 import {viewCards} from "../../card/viewCards";
 import {getNotebookName, pathPosix} from "../../util/pathName";
+import {commonClick} from "../wysiwyg/commonClick";
 
 export class Title {
     public element: HTMLElement;
@@ -245,33 +246,7 @@ export class Title {
             fetchPost("/api/block/getDocInfo", {
                 id: protyle.block.rootID
             }, (response) => {
-                const attrBookmarkElement = hasClosestByClassName(event.target, "protyle-attr--bookmark");
-                if (attrBookmarkElement) {
-                    openFileAttr(response.data.ial, protyle.block.rootID, "bookmark");
-                    event.stopPropagation();
-                    return;
-                }
-
-                const attrNameElement = hasClosestByClassName(event.target, "protyle-attr--name");
-                if (attrNameElement) {
-                    openFileAttr(response.data.ial, protyle.block.rootID, "name");
-                    event.stopPropagation();
-                    return;
-                }
-
-                const attrAliasElement = hasClosestByClassName(event.target, "protyle-attr--alias");
-                if (attrAliasElement) {
-                    openFileAttr(response.data.ial, protyle.block.rootID, "alias");
-                    event.stopPropagation();
-                    return;
-                }
-
-                const attrMemoElement = hasClosestByClassName(event.target, "protyle-attr--memo");
-                if (attrMemoElement) {
-                    openFileAttr(response.data.ial, protyle.block.rootID, "memo");
-                    event.stopPropagation();
-                    return;
-                }
+                commonClick(event, protyle, response.data.ial);
             });
         });
     }

+ 79 - 0
app/src/protyle/wysiwyg/commonClick.ts

@@ -0,0 +1,79 @@
+import {hasClosestByClassName} from "../util/hasClosest";
+import {openAttr, openFileAttr} from "../../menus/commonMenuItem";
+/// #if !MOBILE
+import {openGlobalSearch} from "../../search/util";
+/// #endif
+import {isMobile} from "../../util/functions";
+
+export const commonClick = (event: MouseEvent & {
+    target: HTMLElement
+}, protyle: IProtyle, data?:IObject) => {
+    const isM = isMobile();
+    const attrBookmarkElement = hasClosestByClassName(event.target, "protyle-attr--bookmark");
+    if (attrBookmarkElement) {
+        if (!isM && (event.ctrlKey || event.metaKey)) {
+            /// #if !MOBILE
+            openGlobalSearch(attrBookmarkElement.textContent.trim(), true);
+            /// #endif
+        } else {
+            if (data) {
+                openFileAttr(data, protyle.block.rootID, "bookmark");
+            } else {
+                openAttr(attrBookmarkElement.parentElement.parentElement, protyle, "bookmark");
+            }
+        }
+        event.stopPropagation();
+        return true;
+    }
+
+    const attrNameElement = hasClosestByClassName(event.target, "protyle-attr--name");
+    if (attrNameElement) {
+        if (!isM && (event.ctrlKey || event.metaKey)) {
+            /// #if !MOBILE
+            openGlobalSearch(attrNameElement.textContent.trim(), true);
+            /// #endif
+        } else {
+            if (data ) {
+                openFileAttr(data, protyle.block.rootID, "name");
+            } else {
+                openAttr(attrNameElement.parentElement.parentElement, protyle, "name");
+            }
+        }
+        event.stopPropagation();
+        return true;
+    }
+
+    const attrAliasElement = hasClosestByClassName(event.target, "protyle-attr--alias");
+    if (attrAliasElement) {
+        if (!isM && (event.ctrlKey || event.metaKey)) {
+            /// #if !MOBILE
+            openGlobalSearch(attrAliasElement.textContent.trim(), true);
+            /// #endif
+        } else {
+            if (data) {
+                openFileAttr(data, protyle.block.rootID, "alias");
+            } else {
+                openAttr(attrAliasElement.parentElement.parentElement, protyle, "alias");
+            }
+        }
+        event.stopPropagation();
+        return true;
+    }
+
+    const attrMemoElement = hasClosestByClassName(event.target, "protyle-attr--memo");
+    if (attrMemoElement) {
+        if (!isM && (event.ctrlKey || event.metaKey)) {
+            /// #if !MOBILE
+            openGlobalSearch(attrMemoElement.getAttribute("aria-label").trim(), true);
+            /// #endif
+        } else {
+            if (data) {
+                openFileAttr(data, protyle.block.rootID, "memo");
+            } else {
+                openAttr(attrMemoElement.parentElement.parentElement, protyle, "memo");
+            }
+        }
+        event.stopPropagation();
+        return true;
+    }
+}

+ 2 - 22
app/src/protyle/wysiwyg/index.ts

@@ -63,6 +63,7 @@ import {showMessage} from "../../dialog/message";
 import {getBacklinkHeadingMore, loadBreadcrumb} from "./renderBacklink";
 import {removeSearchMark} from "../toolbar/util";
 import {activeBlur, hideKeyboardToolbar} from "../../mobile/util/keyboardToolbar";
+import {commonClick} from "./commonClick";
 
 export class WYSIWYG {
     public lastHTMLs: { [key: string]: string } = {};
@@ -1718,28 +1719,7 @@ export class WYSIWYG {
                 return;
             }
 
-            const attrBookmarkElement = hasClosestByClassName(event.target, "protyle-attr--bookmark");
-            if (attrBookmarkElement) {
-                openAttr(attrBookmarkElement.parentElement.parentElement, protyle, "bookmark");
-                event.stopPropagation();
-                return;
-            }
-            const attrNameElement = hasClosestByClassName(event.target, "protyle-attr--name");
-            if (attrNameElement) {
-                openAttr(attrNameElement.parentElement.parentElement, protyle, "name");
-                event.stopPropagation();
-                return;
-            }
-            const attrAliasElement = hasClosestByClassName(event.target, "protyle-attr--alias");
-            if (attrAliasElement) {
-                openAttr(attrAliasElement.parentElement.parentElement, protyle, "alias");
-                event.stopPropagation();
-                return;
-            }
-            const attrMemoElement = hasClosestByClassName(event.target, "protyle-attr--memo");
-            if (attrMemoElement) {
-                openAttr(attrMemoElement.parentElement.parentElement, protyle, "memo");
-                event.stopPropagation();
+            if (commonClick(event, protyle)) {
                 return;
             }