🎨 Improve #commonMenu menu (#16147)

This commit is contained in:
Jeffrey Chen 2025-10-18 22:09:56 +08:00 committed by GitHub
parent 2c23d05c7c
commit 3922ca0cd4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 17 additions and 11 deletions

View file

@ -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");

View file

@ -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");
});
};