Browse Source

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

Vanessa 1 year ago
parent
commit
60beaf291d
3 changed files with 93 additions and 34 deletions
  1. 45 19
      app/src/menus/commonMenuItem.ts
  2. 12 15
      app/src/protyle/wysiwyg/index.ts
  3. 36 0
      app/src/window/openNewWindow.ts

+ 45 - 19
app/src/menus/commonMenuItem.ts

@@ -20,6 +20,7 @@ import {Constants} from "../constants";
 import {exportImage} from "../protyle/export/util";
 import {App} from "../index";
 import {renderAVAttribute} from "../protyle/render/av/blockAttr";
+import {openAssetNewWindow} from "../window/openNewWindow";
 
 const bindAttrInput = (inputElement: HTMLInputElement, id: string) => {
     inputElement.addEventListener("change", () => {
@@ -679,12 +680,20 @@ export const exportMd = (id: string) => {
 
 export const openMenu = (app: App, src: string, onlyMenu: boolean, showAccelerator: boolean) => {
     const submenu = [];
+    /// #if MOBILE
+    submenu.push({
+        label: window.siyuan.languages.useBrowserView,
+        accelerator: showAccelerator ? "Click" : "",
+        click: () => {
+            openByMobile(src);
+        }
+    });
+    /// #else
     if (isLocalPath(src)) {
         if (Constants.SIYUAN_ASSETS_EXTS.includes(pathPosix().extname(src)) &&
             (!src.endsWith(".pdf") ||
                 (src.endsWith(".pdf") && !src.startsWith("file://")))
         ) {
-            /// #if !MOBILE
             submenu.push({
                 icon: "iconLayoutRight",
                 label: window.siyuan.languages.insertRight,
@@ -693,26 +702,31 @@ export const openMenu = (app: App, src: string, onlyMenu: boolean, showAccelerat
                     openAsset(app, src.trim(), parseInt(getSearch("page", src)), "right");
                 }
             });
-            /// #endif
+            submenu.push({
+                label: window.siyuan.languages.openBy,
+                icon: "iconOpen",
+                accelerator: showAccelerator ? "⌥Click" : "",
+                click() {
+                    openAsset(app, src.trim(), parseInt(getSearch("page", src)));
+                }
+            });
             /// #if !BROWSER
             submenu.push({
-                label: window.siyuan.languages.useDefault,
-                accelerator: showAccelerator ? "⇧Click" : "",
+                label: window.siyuan.languages.openByNewWindow,
+                icon: "iconOpenWindow",
                 click() {
-                    openBy(src, "app");
+                    openAssetNewWindow(src.trim());
                 }
             });
             /// #endif
         } else {
-            /// #if !BROWSER
             submenu.push({
-                label: window.siyuan.languages.useDefault,
+                label: window.siyuan.languages.useBrowserView,
                 accelerator: showAccelerator ? "Click" : "",
-                click() {
-                    openBy(src, "app");
+                click: () => {
+                    openByMobile(src);
                 }
             });
-            /// #endif
         }
         /// #if !BROWSER
         submenu.push({
@@ -723,8 +737,20 @@ export const openMenu = (app: App, src: string, onlyMenu: boolean, showAccelerat
                 openBy(src, "folder");
             }
         });
+        submenu.push({
+            label: window.siyuan.languages.useDefault,
+            accelerator: showAccelerator ? "⇧Click" : "",
+            click() {
+                openBy(src, "app");
+            }
+        });
         /// #endif
-    } else {
+    } else if (src) {
+        if (0 > src.indexOf(":")) {
+            // 使用 : 判断,不使用 :// 判断 Open external application protocol invalid https://github.com/siyuan-note/siyuan/issues/10075
+            // Support click to open hyperlinks like `www.foo.com` https://github.com/siyuan-note/siyuan/issues/9986
+            src = `https://${src}`;
+        }
         /// #if !BROWSER
         submenu.push({
             label: window.siyuan.languages.useDefault,
@@ -735,16 +761,16 @@ export const openMenu = (app: App, src: string, onlyMenu: boolean, showAccelerat
                 });
             }
         });
+        /// #else
+        submenu.push({
+            label: window.siyuan.languages.useBrowserView,
+            accelerator: showAccelerator ? "Click" : "",
+            click: () => {
+                openByMobile(src);
+            }
+        });
         /// #endif
     }
-    /// #if BROWSER
-    submenu.push({
-        label: window.siyuan.languages.useBrowserView,
-        accelerator: showAccelerator ? "Click" : "",
-        click: () => {
-            openByMobile(src);
-        }
-    });
     /// #endif
     if (onlyMenu) {
         return submenu;

+ 12 - 15
app/src/protyle/wysiwyg/index.ts

@@ -2077,7 +2077,7 @@ export class WYSIWYG {
                 return;
             }
 
-            if (aElement && !event.altKey) {
+            if (aElement) {
                 event.stopPropagation();
                 event.preventDefault();
                 let linkAddress = Lute.UnEscapeHTMLStr(aLink);
@@ -2090,31 +2090,28 @@ export class WYSIWYG {
                         (!linkPathname.endsWith(".pdf") ||
                             (linkPathname.endsWith(".pdf") && !linkAddress.startsWith("file://")))
                     ) {
-                        if (ctrlIsPressed) {
-                            openBy(linkAddress, "folder");
-                        } else if (event.shiftKey) {
-                            openBy(linkAddress, "app");
-                        } else {
+                        if (event.altKey) {
+                            openAsset(protyle.app, linkAddress, parseInt(getSearch("page", linkAddress)));
+                        } else if (!ctrlIsPressed && !event.shiftKey) {
                             openAsset(protyle.app, linkPathname, parseInt(getSearch("page", linkAddress)), "right");
                         }
                     } else {
-                        /// #if !BROWSER
-                        if (ctrlIsPressed) {
-                            openBy(linkAddress, "folder");
-                        } else {
-                            openBy(linkAddress, "app");
-                        }
-                        /// #else
                         openByMobile(linkAddress);
-                        /// #endif
                     }
-                } else if (linkAddress) {
                     /// #if !BROWSER
+                    if (ctrlIsPressed) {
+                        openBy(linkAddress, "folder");
+                    } else if (event.shiftKey) {
+                        openBy(linkAddress, "app");
+                    }
+                    /// #endif
+                } else if (linkAddress) {
                     if (0 > linkAddress.indexOf(":")) {
                         // 使用 : 判断,不使用 :// 判断 Open external application protocol invalid https://github.com/siyuan-note/siyuan/issues/10075
                         // Support click to open hyperlinks like `www.foo.com` https://github.com/siyuan-note/siyuan/issues/9986
                         linkAddress = `https://${linkAddress}`;
                     }
+                    /// #if !BROWSER
                     shell.openExternal(linkAddress).catch((e) => {
                         showMessage(e);
                     });

+ 36 - 0
app/src/window/openNewWindow.ts

@@ -6,6 +6,8 @@ import {Constants} from "../constants";
 import {Tab} from "../layout/Tab";
 import {fetchPost} from "../util/fetch";
 import {showMessage} from "../dialog/message";
+import {getDisplayName, pathPosix} from "../util/pathName";
+import {getSearch} from "../util/functions";
 
 interface windowOptions {
     position?: {
@@ -62,5 +64,39 @@ export const openNewWindowById = (id: string, options: windowOptions = {}) => {
         });
         /// #endif
     });
+};
 
+export const openAssetNewWindow = (assetPath: string, options: windowOptions = {}) => {
+    /// #if !BROWSER
+    const suffix = pathPosix().extname(assetPath.split("?page")[0]);
+    if (Constants.SIYUAN_ASSETS_EXTS.includes(suffix)) {
+        let docIcon = "iconPDF";
+        if (Constants.SIYUAN_ASSETS_IMAGE.includes(suffix)) {
+            docIcon = "iconImage";
+        } else if (Constants.SIYUAN_ASSETS_AUDIO.includes(suffix)) {
+            docIcon = "iconRecord";
+        } else if (Constants.SIYUAN_ASSETS_VIDEO.includes(suffix)) {
+            docIcon = "iconVideo";
+        }
+        const json: any = {
+            title: getDisplayName(assetPath),
+            docIcon,
+            pin: false,
+            active: true,
+            instance: "Tab",
+            action: "Tab",
+            children: {
+                path: assetPath,
+                page: parseInt(getSearch("page", assetPath)),
+                instance: "Asset",
+            }
+        };
+        ipcRenderer.send(Constants.SIYUAN_OPEN_WINDOW, {
+            position: options.position,
+            width: options.width,
+            height: options.height,
+            url: `${window.location.protocol}//${window.location.host}/stage/build/app/window.html?v=${Constants.SIYUAN_VERSION}&json=${encodeURIComponent(JSON.stringify(json))}`
+        });
+    }
+    /// #endif
 };