Переглянути джерело

:art: https://github.com/siyuan-note/siyuan/issues/11133

Vanessa 1 рік тому
батько
коміт
0f6a280513

+ 59 - 2
app/src/boot/globalEvent/command/global.ts

@@ -7,6 +7,9 @@ import {popMenu} from "../../../mobile/menu";
 import {popSearch} from "../../../mobile/menu/search";
 import {popSearch} from "../../../mobile/menu/search";
 import {getRecentDocs} from "../../../mobile/menu/getRecentDocs";
 import {getRecentDocs} from "../../../mobile/menu/getRecentDocs";
 /// #else
 /// #else
+import {openNewWindow} from "../../../window/openNewWindow";
+import {toggleDockBar} from "../../../layout/dock/util";
+import {openGlobalSearch} from "../../../search/util";
 import {workspaceMenu} from "../../../menus/workspace";
 import {workspaceMenu} from "../../../menus/workspace";
 import {isWindow} from "../../../util/functions";
 import {isWindow} from "../../../util/functions";
 import {openRecentDocs} from "../../../business/openRecentDocs";
 import {openRecentDocs} from "../../../business/openRecentDocs";
@@ -14,11 +17,21 @@ import {openSearch} from "../../../search/spread";
 import {goBack, goForward} from "../../../util/backForward";
 import {goBack, goForward} from "../../../util/backForward";
 import {getAllTabs} from "../../../layout/getAll";
 import {getAllTabs} from "../../../layout/getAll";
 import {getInstanceById} from "../../../layout/util";
 import {getInstanceById} from "../../../layout/util";
-import {closeTabByType, getActiveTab, getDockByType, switchTabByIndex} from "../../../layout/tabUtil";
+import {
+    closeTabByType,
+    copyTab,
+    getActiveTab,
+    getDockByType,
+    resizeTabs,
+    switchTabByIndex
+} from "../../../layout/tabUtil";
 import {openSetting} from "../../../config";
 import {openSetting} from "../../../config";
 import {Tab} from "../../../layout/Tab";
 import {Tab} from "../../../layout/Tab";
 import {Files} from "../../../layout/dock/Files";
 import {Files} from "../../../layout/dock/Files";
 /// #endif
 /// #endif
+/// #if !BROWSER
+import {ipcRenderer} from "electron";
+/// #endif
 import {App} from "../../../index";
 import {App} from "../../../index";
 import {Constants} from "../../../constants";
 import {Constants} from "../../../constants";
 import {setReadOnly} from "../../../config/util/setReadOnly";
 import {setReadOnly} from "../../../config/util/setReadOnly";
@@ -51,7 +64,7 @@ const selectOpenTab = () => {
     }
     }
     dockFile.toggleModel("file", true);
     dockFile.toggleModel("file", true);
     /// #endif
     /// #endif
-}
+};
 
 
 export const globalCommand = (command: string, app: App) => {
 export const globalCommand = (command: string, app: App) => {
     /// #if MOBILE
     /// #if MOBILE
@@ -110,6 +123,9 @@ export const globalCommand = (command: string, app: App) => {
                 key: (getSelection().rangeCount > 0 ? getSelection().getRangeAt(0) : document.createRange()).toString()
                 key: (getSelection().rangeCount > 0 ? getSelection().getRangeAt(0) : document.createRange()).toString()
             });
             });
             return true;
             return true;
+        case "stickSearch":
+            openGlobalSearch(app, (getSelection().rangeCount > 0 ? getSelection().getRangeAt(0) : document.createRange()).toString(), true);
+            return true;
         case "goBack":
         case "goBack":
             goBack(app);
             goBack(app);
             return true;
             return true;
@@ -157,6 +173,15 @@ export const globalCommand = (command: string, app: App) => {
         case "recentDocs":
         case "recentDocs":
             openRecentDocs();
             openRecentDocs();
             return true;
             return true;
+        case "toggleDock":
+            toggleDockBar(document.querySelector("#barDock use"));
+            return true;
+        case "toggleWin":
+            /// #if !BROWSER
+            ipcRenderer.send(Constants.SIYUAN_CMD, "hide");
+            ipcRenderer.send(Constants.SIYUAN_CMD, "minimize");
+            /// #endif
+            return true;
     }
     }
     if (command === "goToEditTabNext" || command === "goToEditTabPrev") {
     if (command === "goToEditTabNext" || command === "goToEditTabPrev") {
         let currentTabElement = document.querySelector(".layout__wnd--active ul.layout-tab-bar > .item--focus");
         let currentTabElement = document.querySelector(".layout__wnd--active ul.layout-tab-bar > .item--focus");
@@ -265,6 +290,38 @@ export const globalCommand = (command: string, app: App) => {
         }
         }
         return true;
         return true;
     }
     }
+    if (command === "splitLR") {
+        const tab = getActiveTab(false);
+        if (tab) {
+            tab.parent.split("lr").addTab(copyTab(app, tab));
+        }
+        return true;
+    }
+    if (command === "splitTB") {
+        const tab = getActiveTab(false);
+        if (tab) {
+            tab.parent.split("tb").addTab(copyTab(app, tab));
+        }
+        return true;
+    }
+    if (command === "splitMoveB" || command === "splitMoveR") {
+        const tab = getActiveTab(false);
+        if (tab && tab.parent.children.length > 1) {
+            const newWnd = tab.parent.split(command === "splitMoveB" ? "tb" : "lr");
+            newWnd.headersElement.append(tab.headElement);
+            newWnd.headersElement.parentElement.classList.remove("fn__none");
+            newWnd.moveTab(tab);
+            resizeTabs();
+        }
+        return true;
+    }
+    if (command === "tabToWindow") {
+        const tab = getActiveTab(false);
+        if (tab) {
+            openNewWindow(tab);
+        }
+        return true;
+    }
     /// #endif
     /// #endif
 
 
     switch (command) {
     switch (command) {

+ 4 - 4
app/src/boot/globalEvent/command/panel.ts

@@ -59,10 +59,10 @@ export const commandPanel = (app: App) => {
             "goForward", "goToEditTabNext", "goToEditTabPrev", "goToTab1", "goToTab2", "goToTab3", "goToTab4",
             "goForward", "goToEditTabNext", "goToEditTabPrev", "goToTab1", "goToTab2", "goToTab3", "goToTab4",
             "goToTab5", "goToTab6", "goToTab7", "goToTab8", "goToTab9", "goToTabNext", "goToTabPrev", "lockScreen",
             "goToTab5", "goToTab6", "goToTab7", "goToTab8", "goToTab9", "goToTabNext", "goToTabPrev", "lockScreen",
             "mainMenu", "move", "newFile", "recentDocs", "replace", "riffCard", "search", "selectOpen1", "syncNow",
             "mainMenu", "move", "newFile", "recentDocs", "replace", "riffCard", "search", "selectOpen1", "syncNow",
-
-            "splitLR", "splitMoveB", "splitMoveR", "splitTB", "stickSearch", "tabToWindow",
-            "toggleDock", "toggleWin"];
-
+            "splitLR", "splitMoveB", "splitMoveR", "splitTB", "tabToWindow", "stickSearch", "toggleDock"];
+        /// #if !BROWSER
+        keys.push("toggleWin");
+        /// #endif
         /// #endif
         /// #endif
         if (keys.includes(key)) {
         if (keys.includes(key)) {
             html += `<li class="b3-list-item" data-command="${key}">
             html += `<li class="b3-list-item" data-command="${key}">

+ 24 - 32
app/src/boot/globalEvent/keydown.ts

@@ -1514,44 +1514,36 @@ export const windowKeyDown = (app: App, event: KeyboardEvent) => {
         event.preventDefault();
         event.preventDefault();
         return;
         return;
     }
     }
-    if ((
-        matchHotKey(window.siyuan.config.keymap.general.splitLR.custom, event) ||
-        matchHotKey(window.siyuan.config.keymap.general.splitMoveR.custom, event) ||
-        matchHotKey(window.siyuan.config.keymap.general.splitTB.custom, event) ||
-        matchHotKey(window.siyuan.config.keymap.general.tabToWindow.custom, event) ||
-        matchHotKey(window.siyuan.config.keymap.general.splitMoveB.custom, event)
-    ) && !event.repeat) {
-        event.preventDefault();
-        const tab = getActiveTab(false);
-        if (tab) {
-            if (matchHotKey(window.siyuan.config.keymap.general.tabToWindow.custom, event)) {
-                openNewWindow(tab);
-            } else if (matchHotKey(window.siyuan.config.keymap.general.splitLR.custom, event)) {
-                tab.parent.split("lr").addTab(copyTab(app, tab));
-            } else if (matchHotKey(window.siyuan.config.keymap.general.splitTB.custom, event)) {
-                tab.parent.split("tb").addTab(copyTab(app, tab));
-            } else if (tab.parent.children.length > 1) {
-                const newWnd = tab.parent.split(matchHotKey(window.siyuan.config.keymap.general.splitMoveB.custom, event) ? "tb" : "lr");
-                newWnd.headersElement.append(tab.headElement);
-                newWnd.headersElement.parentElement.classList.remove("fn__none");
-                newWnd.moveTab(tab);
-                resizeTabs();
-            }
-        }
+    if (matchHotKey(window.siyuan.config.keymap.general.splitLR.custom, event) && !event.repeat) {
+        event.preventDefault();
+        globalCommand("splitLR", app);
+        return;
+    }
+    if (matchHotKey(window.siyuan.config.keymap.general.splitMoveR.custom, event) && !event.repeat) {
+        event.preventDefault();
+        globalCommand("splitMoveR", app);
+        return;
+    }
+    if (matchHotKey(window.siyuan.config.keymap.general.splitTB.custom, event) && !event.repeat) {
+        event.preventDefault();
+        globalCommand("splitTB", app);
+        return;
+    }
+    if (matchHotKey(window.siyuan.config.keymap.general.tabToWindow.custom, event) && !event.repeat) {
+        event.preventDefault();
+        globalCommand("tabToWindow", app);
+        return;
+    }
+    if (matchHotKey(window.siyuan.config.keymap.general.splitMoveB.custom, event) && !event.repeat) {
+        event.preventDefault();
+        globalCommand("splitMoveB", app);
         return;
         return;
     }
     }
-
     if (matchHotKey(window.siyuan.config.keymap.general.stickSearch.custom, event)) {
     if (matchHotKey(window.siyuan.config.keymap.general.stickSearch.custom, event)) {
-        if (getSelection().rangeCount > 0) {
-            const range = getSelection().getRangeAt(0);
-            openGlobalSearch(app, range.toString(), true);
-        } else {
-            openGlobalSearch(app, "", true);
-        }
+        globalCommand("stickSearch", app);
         event.preventDefault();
         event.preventDefault();
         return;
         return;
     }
     }
-
     if (editKeydown(app, event)) {
     if (editKeydown(app, event)) {
         return;
         return;
     }
     }