浏览代码

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

Vanessa 1 年之前
父节点
当前提交
1c0732eae1
共有 4 个文件被更改,包括 33 次插入34 次删除
  1. 20 0
      app/src/menus/protyle.ts
  2. 2 17
      app/src/protyle/gutter/index.ts
  3. 9 4
      app/src/protyle/wysiwyg/index.ts
  4. 2 13
      app/src/protyle/wysiwyg/keydown.ts

+ 20 - 0
app/src/menus/protyle.ts

@@ -43,6 +43,7 @@ import {alignImgCenter, alignImgLeft} from "../protyle/wysiwyg/commonHotkey";
 import {renameTag} from "../util/noRelyPCFunction";
 import {hideElements} from "../protyle/ui/hideElements";
 import {emitOpenMenu} from "../plugin/EventBus";
+import {openMobileFileById} from "../mobile/editor";
 
 export const fileAnnotationRefMenu = (protyle: IProtyle, refElement: HTMLElement) => {
     const nodeElement = hasClosestBlock(refElement);
@@ -531,6 +532,25 @@ export const contentMenu = (protyle: IProtyle, nodeElement: Element) => {
     }
 };
 
+export const enterBack = (protyle: IProtyle, id: string) => {
+    if (!protyle.block.showAll) {
+        const ids = protyle.path.split("/");
+        if (ids.length > 2) {
+            /// #if MOBILE
+            openMobileFileById(protyle.app, ids[ids.length - 2], [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]);
+            /// #else
+            openFileById({
+                app: protyle.app,
+                id: ids[ids.length - 2],
+                action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]
+            });
+            /// #endif
+        }
+    } else {
+        zoomOut({protyle, id: protyle.block.parent2ID, focusId: id});
+    }
+}
+
 export const zoomOut = (options: {
     protyle: IProtyle,
     id: string,

+ 2 - 17
app/src/protyle/gutter/index.ts

@@ -1,6 +1,6 @@
 import {hasClosestBlock, hasClosestByAttribute, hasClosestByMatchTag, hasClosestByTag} from "../util/hasClosest";
 import {getIconByType} from "../../editor/getIcon";
-import {iframeMenu, setFold, tableMenu, videoMenu, zoomOut} from "../../menus/protyle";
+import {enterBack, iframeMenu, setFold, tableMenu, videoMenu, zoomOut} from "../../menus/protyle";
 import {MenuItem} from "../../menus/Menu";
 import {copySubMenu, openAttr, openWechatNotify} from "../../menus/commonMenuItem";
 import {copyPlainText, updateHotkeyTip, writeText} from "../util/compatibility";
@@ -1427,22 +1427,7 @@ export class Gutter {
                 accelerator: window.siyuan.config.keymap.general.enterBack.custom,
                 label: window.siyuan.languages.enterBack,
                 click: () => {
-                    if (!protyle.block.showAll) {
-                        const ids = protyle.path.split("/");
-                        if (ids.length > 2) {
-                            /// #if MOBILE
-                            openMobileFileById(protyle.app, ids[ids.length - 2], [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]);
-                            /// #else
-                            openFileById({
-                                app: protyle.app,
-                                id: ids[ids.length - 2],
-                                action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]
-                            });
-                            /// #endif
-                        }
-                    } else {
-                        zoomOut({protyle, id: protyle.block.parent2ID, focusId: id});
-                    }
+                    enterBack(protyle, id);
                 }
             }).element);
         }

+ 9 - 4
app/src/protyle/wysiwyg/index.ts

@@ -21,7 +21,7 @@ import {isLocalPath, pathPosix} from "../../util/pathName";
 import {genEmptyElement} from "../../block/util";
 import {previewImage} from "../preview/image";
 import {
-    contentMenu,
+    contentMenu, enterBack,
     fileAnnotationRefMenu,
     imgMenu,
     linkMenu,
@@ -1933,6 +1933,7 @@ export class WYSIWYG {
                         clientY: event.clientY
                     });
                 } else if (actionElement.parentElement.classList.contains("li")) {
+                    const actionId = actionElement.parentElement.getAttribute("data-node-id")
                     if (event.altKey && !protyle.disabled) {
                         // 展开/折叠当前层级的所有列表项
                         if (actionElement.parentElement.parentElement.classList.contains("protyle-wysiwyg")) {
@@ -1964,7 +1965,7 @@ export class WYSIWYG {
                     } else if (event.shiftKey && !protyle.disabled) {
                         openAttr(actionElement.parentElement);
                     } else if (ctrlIsPressed) {
-                        zoomOut({protyle, id: actionElement.parentElement.getAttribute("data-node-id")});
+                        zoomOut({protyle, id: actionId});
                     } else {
                         if (actionElement.classList.contains("protyle-action--task")) {
                             if (!protyle.disabled) {
@@ -1977,10 +1978,14 @@ export class WYSIWYG {
                                     actionElement.parentElement.classList.add("protyle-task--done");
                                 }
                                 actionElement.parentElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));
-                                updateTransaction(protyle, actionElement.parentElement.getAttribute("data-node-id"), actionElement.parentElement.outerHTML, html);
+                                updateTransaction(protyle, actionId, actionElement.parentElement.outerHTML, html);
                             }
                         } else {
-                            zoomOut({protyle, id: actionElement.parentElement.getAttribute("data-node-id")});
+                            if (protyle.block.id === actionId) {
+                                enterBack(protyle, actionId);
+                            } else {
+                                zoomOut({protyle, id: actionId});
+                            }
                         }
                     }
                 }

+ 2 - 13
app/src/protyle/wysiwyg/keydown.ts

@@ -52,7 +52,7 @@ import {
     goHome,
     upSelect
 } from "./commonHotkey";
-import {fileAnnotationRefMenu, linkMenu, refMenu, setFold, tagMenu, zoomOut} from "../../menus/protyle";
+import {enterBack, fileAnnotationRefMenu, linkMenu, refMenu, setFold, tagMenu, zoomOut} from "../../menus/protyle";
 import {removeEmbed} from "./removeEmbed";
 import {openAttr} from "../../menus/commonMenuItem";
 import {Constants} from "../../constants";
@@ -445,18 +445,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
         }
 
         if (matchHotKey(window.siyuan.config.keymap.general.enterBack.custom, event)) {
-            if (!protyle.block.showAll) {
-                const ids = protyle.path.split("/");
-                if (ids.length > 2) {
-                    openFileById({
-                        app: protyle.app,
-                        id: ids[ids.length - 2],
-                        action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]
-                    });
-                }
-            } else {
-                zoomOut({protyle, id: protyle.block.parent2ID, focusId: nodeElement.getAttribute("data-node-id")});
-            }
+            enterBack(protyle, nodeElement.getAttribute("data-node-id"));
             event.preventDefault();
             event.stopPropagation();
             return;