diff --git a/app/src/block/Panel.ts b/app/src/block/Panel.ts index c72ebf302ef..c1087d70579 100644 --- a/app/src/block/Panel.ts +++ b/app/src/block/Panel.ts @@ -228,7 +228,7 @@ export class BlockPanel { this.targetElement = undefined; // 移除弹出上使用右键菜单 const menuLevel = parseInt(window.siyuan.menus.menu.element.dataset.from); - if (window.siyuan.menus.menu.element.dataset.from !== "app" && menuLevel && menuLevel >= level) { + if (menuLevel && menuLevel >= level && window.siyuan.menus.menu.element.dataset.from.includes("popover")) { // https://github.com/siyuan-note/siyuan/issues/9854 右键菜单不是从浮窗中弹出的则不进行移除 window.siyuan.menus.menu.remove(); } diff --git a/app/src/constants.ts b/app/src/constants.ts index c70af267199..aed6de001ad 100644 --- a/app/src/constants.ts +++ b/app/src/constants.ts @@ -236,13 +236,15 @@ export abstract class Constants { public static readonly MENU_BLOCK_SINGLE = "block-single"; // 单选块菜单 public static readonly MENU_BLOCK_MULTI = "block-multi"; // 多选块菜单 public static readonly MENU_TITLE = "titleMenu"; // 文档块菜单 + public static readonly MENU_FROM_TITLE_PROTYLE = "title-protyle"; // 在 Protyle 触发的文档块菜单 + public static readonly MENU_FROM_TITLE_BREADCRUMB = "title-breadcrumb"; // 在面包屑触发的文档块菜单 public static readonly MENU_BREADCRUMB_MORE = "breadcrumbMore"; // 面包屑更多菜单 public static readonly MENU_BREADCRUMB_MOBILE_PATH = "breadcrumb-mobile-path"; // 移动端面包屑菜单 public static readonly MENU_DOC_TREE_MORE = "docTreeMore"; // 侧栏文档树右键菜单 - public static readonly MENU_DOC_TREE_MORE_NOTEBOOK = "docTreeMore-notebook"; // 侧栏文档树右键菜单,单个笔记本 - public static readonly MENU_DOC_TREE_MORE_DOC = "docTreeMore-doc"; // 侧栏文档树右键菜单,单个文档 - public static readonly MENU_DOC_TREE_MORE_DOCS = "docTreeMore-docs"; // 侧栏文档树右键菜单,多个文档 + public static readonly MENU_FROM_DOC_TREE_MORE_NOTEBOOK = "tree-notebook"; // 侧栏文档树右键菜单,单个笔记本 + public static readonly MENU_FROM_DOC_TREE_MORE_DOC = "tree-doc"; // 侧栏文档树右键菜单,单个文档 + public static readonly MENU_FROM_DOC_TREE_MORE_DOCS = "tree-docs"; // 侧栏文档树右键菜单,多个文档 public static readonly MENU_TAG = "tagMenu"; // 侧栏标签菜单 public static readonly MENU_BOOKMARK = "bookmarkMenu"; // 侧栏书签菜单 public static readonly MENU_OUTLINE_CONTEXT = "outline-context"; // 大纲标题右键菜单 diff --git a/app/src/menus/Menu.ts b/app/src/menus/Menu.ts index 209c91cc7d5..8d7915b9ec1 100644 --- a/app/src/menus/Menu.ts +++ b/app/src/menus/Menu.ts @@ -120,7 +120,7 @@ export class Menu { this.element.classList.remove("b3-menu--list", "b3-menu--fullscreen"); this.element.removeAttribute("style"); // zIndex this.element.removeAttribute("data-name"); // 标识再次点击不消失 - this.element.removeAttribute("data-from"); // 标识是否在浮窗内打开 + this.element.removeAttribute("data-from"); // 标识菜单入口 this.data = undefined; // 移除数据 } diff --git a/app/src/menus/navigation.ts b/app/src/menus/navigation.ts index da764a800ac..aa3ec72d8f0 100644 --- a/app/src/menus/navigation.ts +++ b/app/src/menus/navigation.ts @@ -32,6 +32,7 @@ import {openByMobile} from "../protyle/util/compatibility"; import {addFilesToDatabase} from "../protyle/render/av/addToDatabase"; const initMultiMenu = (selectItemElements: NodeListOf, app: App) => { + window.siyuan.menus.menu.element.setAttribute("data-from", Constants.MENU_FROM_DOC_TREE_MORE_DOCS); const fileItemElement = Array.from(selectItemElements).find(item => { if (item.getAttribute("data-type") === "navigation-file") { return true; @@ -203,6 +204,8 @@ export const initNavigationMenu = (app: App, liElement: HTMLElement) => { const selectItemElements = fileElement.querySelectorAll(".b3-list-item--focus"); if (selectItemElements.length > 1) { return initMultiMenu(selectItemElements, app); + } else { + window.siyuan.menus.menu.element.setAttribute("data-from", Constants.MENU_FROM_DOC_TREE_MORE_NOTEBOOK); } const notebookId = liElement.parentElement.getAttribute("data-url"); const name = getNotebookName(notebookId); @@ -708,6 +711,7 @@ export const initFileMenu = (app: App, notebookId: string, pathString: string, l separatorPosition: "top", }); } + window.siyuan.menus.menu.element.setAttribute("data-from", Constants.MENU_FROM_DOC_TREE_MORE_DOC); return window.siyuan.menus.menu; }; diff --git a/app/src/protyle/breadcrumb/index.ts b/app/src/protyle/breadcrumb/index.ts index 48d55556e0c..70e09aa80c0 100644 --- a/app/src/protyle/breadcrumb/index.ts +++ b/app/src/protyle/breadcrumb/index.ts @@ -97,7 +97,7 @@ ${padHTML} }); } else { const targetRect = target.getBoundingClientRect(); - openTitleMenu(protyle, {x: targetRect.right, y: targetRect.bottom, isLeft: true}); + openTitleMenu(protyle, {x: targetRect.right, y: targetRect.bottom, isLeft: true}, Constants.MENU_FROM_TITLE_BREADCRUMB); } event.stopPropagation(); event.preventDefault(); diff --git a/app/src/protyle/header/Title.ts b/app/src/protyle/header/Title.ts index 5aa47dbbdaa..a2008d05934 100644 --- a/app/src/protyle/header/Title.ts +++ b/app/src/protyle/header/Title.ts @@ -194,7 +194,7 @@ export class Title { }); } else { const iconRect = iconElement.getBoundingClientRect(); - openTitleMenu(protyle, {x: iconRect.left, y: iconRect.bottom}); + openTitleMenu(protyle, {x: iconRect.left, y: iconRect.bottom}, Constants.MENU_FROM_TITLE_PROTYLE); } }); this.element.addEventListener("contextmenu", (event) => { @@ -202,7 +202,7 @@ export class Title { return; } if (getSelection().rangeCount === 0 || iconElement.contains((event.target as HTMLElement))) { - openTitleMenu(protyle, {x: event.clientX, y: event.clientY}); + openTitleMenu(protyle, {x: event.clientX, y: event.clientY}, Constants.MENU_FROM_TITLE_PROTYLE); return; } protyle.toolbar?.element.classList.add("fn__none"); diff --git a/app/src/protyle/header/openTitleMenu.ts b/app/src/protyle/header/openTitleMenu.ts index 8bf1cc2bbb4..fd20af0db9e 100644 --- a/app/src/protyle/header/openTitleMenu.ts +++ b/app/src/protyle/header/openTitleMenu.ts @@ -26,7 +26,7 @@ import {addEditorToDatabase} from "../render/av/addToDatabase"; import {openFileById} from "../../editor/util"; import {hasTopClosestByClassName} from "../util/hasClosest"; -export const openTitleMenu = (protyle: IProtyle, position: IPosition) => { +export const openTitleMenu = (protyle: IProtyle, position: IPosition, from: string) => { hideTooltip(); if (!window.siyuan.menus.menu.element.classList.contains("fn__none") && window.siyuan.menus.menu.element.getAttribute("data-name") === Constants.MENU_TITLE) { @@ -38,6 +38,8 @@ export const openTitleMenu = (protyle: IProtyle, position: IPosition) => { }, (response) => { window.siyuan.menus.menu.remove(); window.siyuan.menus.menu.element.setAttribute("data-name", Constants.MENU_TITLE); + const popoverElement = hasTopClosestByClassName(protyle.element, "block__popover", true); + window.siyuan.menus.menu.element.setAttribute("data-from", popoverElement ? popoverElement.dataset.level + "popover-" + from : "app-" + from); window.siyuan.menus.menu.append(new MenuItem({ id: "copy", label: window.siyuan.languages.copy, @@ -293,7 +295,5 @@ export const openTitleMenu = (protyle: IProtyle, position: IPosition) => { /// #else window.siyuan.menus.menu.popup(position); /// #endif - const popoverElement = hasTopClosestByClassName(protyle.element, "block__popover", true); - window.siyuan.menus.menu.element.setAttribute("data-from", popoverElement ? popoverElement.dataset.level + "popover" : "app"); }); };