From 1c0732eae1dbaa56dd7b22e8d5fa504d98f30460 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Sun, 20 Aug 2023 12:41:00 +0800 Subject: [PATCH] :art: fix https://github.com/siyuan-note/siyuan/issues/9004 --- app/src/menus/protyle.ts | 20 ++++++++++++++++++++ app/src/protyle/gutter/index.ts | 19 ++----------------- app/src/protyle/wysiwyg/index.ts | 13 +++++++++---- app/src/protyle/wysiwyg/keydown.ts | 15 ++------------- 4 files changed, 33 insertions(+), 34 deletions(-) diff --git a/app/src/menus/protyle.ts b/app/src/menus/protyle.ts index d0037622d..2a5395a31 100644 --- a/app/src/menus/protyle.ts +++ b/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, diff --git a/app/src/protyle/gutter/index.ts b/app/src/protyle/gutter/index.ts index 3e42678f0..6dfb18714 100644 --- a/app/src/protyle/gutter/index.ts +++ b/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); } diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts index e2732a538..c32b3c0fd 100644 --- a/app/src/protyle/wysiwyg/index.ts +++ b/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}); + } } } } diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts index 28abe1766..8b4467c71 100644 --- a/app/src/protyle/wysiwyg/keydown.ts +++ b/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;