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

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

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

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

@@ -5,7 +5,11 @@ import {Editor} from "../../../editor";
 import {openDock} from "../../../mobile/dock/util";
 import {popMenu} from "../../../mobile/menu";
 import {popSearch} from "../../../mobile/menu/search";
+import {getRecentDocs} from "../../../mobile/menu/getRecentDocs";
 /// #else
+import {workspaceMenu} from "../../../menus/workspace";
+import {isWindow} from "../../../util/functions";
+import {openRecentDocs} from "../../../business/openRecentDocs";
 import {openSearch} from "../../../search/spread";
 import {goBack, goForward} from "../../../util/backForward";
 import {getAllTabs} from "../../../layout/getAll";
@@ -17,6 +21,8 @@ import {Tab} from "../../../layout/Tab";
 import {App} from "../../../index";
 import {Constants} from "../../../constants";
 import {setReadOnly} from "../../../config/util/setReadOnly";
+import {lockScreen} from "../../../dialog/processSystem";
+import {newFile} from "../../../util/newFile";
 
 export const globalCommand = (command: string, app: App) => {
     /// #if MOBILE
@@ -33,12 +39,15 @@ export const globalCommand = (command: string, app: App) => {
         case "backlinks":
             openDock("backlink");
             return true;
-        case "config":
+        case "mainMenu":
             popMenu();
             return true;
         case "globalSearch":
             popSearch(app);
             return true;
+        case "recentDocs":
+            getRecentDocs(app);
+            return true;
     }
     /// #else
     switch (command) {
@@ -110,7 +119,14 @@ export const globalCommand = (command: string, app: App) => {
         case "goToTabPrev":
             switchTabByIndex(-2);
             return true;
-
+        case "mainMenu":
+            if (!isWindow()) {
+                workspaceMenu(app, document.querySelector("#barWorkspace").getBoundingClientRect());
+            }
+            return true;
+        case "recentDocs":
+            openRecentDocs();
+            return true;
     }
     if (command === "goToEditTabNext" || command === "goToEditTabPrev") {
         let currentTabElement = document.querySelector(".layout__wnd--active ul.layout-tab-bar > .item--focus");
@@ -231,6 +247,15 @@ export const globalCommand = (command: string, app: App) => {
         case "editReadonly":
             setReadOnly(!window.siyuan.config.editor.readOnly);
             return true;
+        case "lockScreen":
+            lockScreen(app);
+            return true;
+        case "newFile":
+            newFile({
+                app,
+                useSavePath: true
+            });
+            return true;
     }
 
     return false;

+ 45 - 7
app/src/boot/globalEvent/command/panel.ts

@@ -15,9 +15,11 @@ import {Files} from "../../../layout/dock/Files";
 import {Search} from "../../../search";
 /// #endif
 import {addEditorToDatabase, addFilesToDatabase} from "../../../protyle/render/av/addToDatabase";
-import {hasClosestByClassName} from "../../../protyle/util/hasClosest";
-import {onluProtyleCommand} from "./protyle";
+import {hasClosestBlock, hasClosestByClassName} from "../../../protyle/util/hasClosest";
+import {onlyProtyleCommand} from "./protyle";
 import {globalCommand} from "./global";
+import {getTopPaths, movePathTo, moveToPath} from "../../../util/pathName";
+import {hintMoveBlock} from "../../../protyle/hint/extend";
 
 export const commandPanel = (app: App) => {
     const range = getSelection().rangeCount > 0 ? getSelection().getRangeAt(0) : undefined;
@@ -44,14 +46,24 @@ export const commandPanel = (app: App) => {
     Object.keys(window.siyuan.config.keymap.general).forEach((key) => {
         let keys;
         /// #if MOBILE
-        keys = ["addToDatabase", "fileTree", "outline", "bookmark", "tag", "dailyNote", "inbox", "backlinks", "config",
-            "dataHistory", "editReadonly", "enter", "enterBack", "globalSearch"];
+        keys = ["addToDatabase", "fileTree", "outline", "bookmark", "tag", "dailyNote", "inbox", "backlinks",
+            "dataHistory", "editReadonly", "enter", "enterBack", "globalSearch",
+            "lockScreen", "mainMenu", "move", "newFile", "recentDocs",
+
+            "replace", "riffCard", "search", "selectOpen1",
+            "splitLR", "splitMoveB", "splitMoveR", "splitTB", "stickSearch", "syncNow", "tabToWindow",
+            "toggleDock", "toggleWin"];
         /// #else
         keys = ["addToDatabase", "fileTree", "outline", "bookmark", "tag", "dailyNote", "inbox", "backlinks",
             "graphView", "globalGraph", "closeAll", "closeLeft", "closeOthers", "closeRight", "closeTab",
             "closeUnmodified", "config", "dataHistory", "editReadonly", "enter", "enterBack", "globalSearch", "goBack",
             "goForward", "goToEditTabNext", "goToEditTabPrev", "goToTab1", "goToTab2", "goToTab3", "goToTab4",
-            "goToTab5", "goToTab6", "goToTab7", "goToTab8", "goToTab9", "goToTabNext", "goToTabPrev"];
+            "goToTab5", "goToTab6", "goToTab7", "goToTab8", "goToTab9", "goToTabNext", "goToTabPrev", "lockScreen",
+            "mainMenu", "move", "newFile", "recentDocs",
+
+            "replace", "riffCard", "search", "selectOpen1",
+            "splitLR", "splitMoveB", "splitMoveR", "splitTB", "stickSearch", "syncNow", "tabToWindow",
+            "toggleDock", "toggleWin"];
 
         /// #endif
         if (keys.includes(key)) {
@@ -66,6 +78,7 @@ export const commandPanel = (app: App) => {
         plugin.commands.forEach(command => {
             const liElement = document.createElement("li");
             liElement.classList.add("b3-list-item");
+            liElement.dataset.command = command.langKey;
             liElement.innerHTML = `<span class="b3-list-item__text">${plugin.displayName}: ${command.langText || plugin.i18n[command.langKey]}</span>
 <span class="b3-list-item__meta${isMobile() ? " fn__none" : ""}">${updateHotkeyTip(command.customHotkey)}</span>`;
             liElement.addEventListener("click", () => {
@@ -145,7 +158,9 @@ const filterList = (inputElement: HTMLInputElement, listElement: Element) => {
     let hasFocus = false;
     Array.from(listElement.children).forEach((element: HTMLElement) => {
         const elementValue = element.querySelector(".b3-list-item__text").textContent.toLowerCase();
-        if (inputValue.indexOf(elementValue) > -1 || elementValue.indexOf(inputValue) > -1) {
+        const command = element.dataset.command;
+        if (inputValue.indexOf(elementValue) > -1 || elementValue.indexOf(inputValue) > -1 ||
+            inputValue.indexOf(command) > -1 || command.indexOf(inputValue) > -1) {
             if (!hasFocus) {
                 element.classList.add("b3-list-item--focus");
             }
@@ -266,7 +281,7 @@ export const execByCommand = (options: {
     }
 
     // only protyle
-    if (!isFileFocus && onluProtyleCommand({
+    if (!isFileFocus && onlyProtyleCommand({
         command: options.command,
         previousRange: range,
         protyle
@@ -292,5 +307,28 @@ export const execByCommand = (options: {
                 addFilesToDatabase(fileLiElements);
             }
             break;
+        case "move":
+            if (!isFileFocus) {
+                const nodeElement = hasClosestBlock(range.startContainer);
+                if (protyle.title?.editElement.contains(range.startContainer) || !nodeElement) {
+                    movePathTo((toPath, toNotebook) => {
+                        moveToPath([protyle.path], toNotebook[0], toPath[0]);
+                    }, [protyle.path], range);
+                } else if (nodeElement && range && protyle.element.contains(range.startContainer)) {
+                    let selectElements = Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select"));
+                    if (selectElements.length === 0) {
+                        selectElements = [nodeElement];
+                    }
+                    movePathTo((toPath) => {
+                        hintMoveBlock(toPath[0], selectElements, protyle);
+                    });
+                }
+            } else {
+                const paths = getTopPaths(fileLiElements);
+                movePathTo((toPath, toNotebook) => {
+                    moveToPath(paths, toNotebook[0], toPath[0]);
+                }, paths);
+            }
+            break;
     }
 };

+ 1 - 1
app/src/boot/globalEvent/command/protyle.ts

@@ -2,7 +2,7 @@ import {hasClosestBlock} from "../../../protyle/util/hasClosest";
 import {getTopAloneElement} from "../../../protyle/wysiwyg/getBlock";
 import {enterBack, zoomOut} from "../../../menus/protyle";
 
-export const onluProtyleCommand = (options: {
+export const onlyProtyleCommand = (options: {
     command: string,
     previousRange: Range,
     protyle: IProtyle,

+ 11 - 23
app/src/boot/globalEvent/keydown.ts

@@ -330,25 +330,12 @@ const editKeydown = (app: App, event: KeyboardEvent) => {
         return true;
     }
     if (!isFileFocus && matchHotKey(window.siyuan.config.keymap.general.move.custom, event)) {
-        let range: Range;
-        let nodeElement: false | HTMLElement;
-        if (getSelection().rangeCount > 0) {
-            range = getSelection().getRangeAt(0);
-            nodeElement = hasClosestBlock(range.startContainer);
-        }
-        if (protyle.title?.editElement.contains(range.startContainer)) {
-            movePathTo((toPath, toNotebook) => {
-                moveToPath([protyle.path], toNotebook[0], toPath[0]);
-            }, [protyle.path], range);
-        } else if (nodeElement && range && protyle.element.contains(range.startContainer)) {
-            let selectElements = Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select"));
-            if (selectElements.length === 0) {
-                selectElements = [nodeElement];
-            }
-            movePathTo((toPath) => {
-                hintMoveBlock(toPath[0], selectElements, protyle);
-            });
-        }
+        execByCommand({
+            command: "move",
+            app,
+            protyle,
+            previousRange: range
+        });
         event.preventDefault();
         return true;
     }
@@ -671,10 +658,11 @@ const fileTreeKeydown = (app: App, event: KeyboardEvent) => {
 
     if (isFile && matchHotKey(window.siyuan.config.keymap.general.move.custom, event)) {
         window.siyuan.menus.menu.remove();
-        const pathes = getTopPaths(liElements);
-        movePathTo((toPath, toNotebook) => {
-            moveToPath(pathes, toNotebook[0], toPath[0]);
-        }, pathes);
+        execByCommand({
+            command: "move",
+            app,
+            fileLiElements: liElements
+        });
         event.preventDefault();
         return true;
     }

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

@@ -67,7 +67,7 @@ import {avKeydown} from "../render/av/keydown";
 import {checkFold} from "../../util/noRelyPCFunction";
 import {AIActions} from "../../ai/actions";
 import {openLink} from "../../editor/openLink";
-import {onluProtyleCommand} from "../../boot/globalEvent/command/protyle";
+import {onlyProtyleCommand} from "../../boot/globalEvent/command/protyle";
 
 export const getContentByInlineHTML = (range: Range, cb: (content: string) => void) => {
     let html = "";
@@ -469,7 +469,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
         }
 
         if (matchHotKey(window.siyuan.config.keymap.general.enter.custom, event)) {
-            onluProtyleCommand({
+            onlyProtyleCommand({
                 protyle,
                 command: "enter",
                 previousRange: range,
@@ -480,7 +480,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
         }
 
         if (matchHotKey(window.siyuan.config.keymap.general.enterBack.custom, event)) {
-            onluProtyleCommand({
+            onlyProtyleCommand({
                 protyle,
                 command: "enterBack",
                 previousRange: range,