Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/src/block/Panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Copy link

Copilot AI Oct 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential null reference error. dataset.from may be undefined if the attribute hasn't been set. Add a null check before calling .includes(): window.siyuan.menus.menu.element.dataset.from?.includes('popover')

Suggested change
if (menuLevel && menuLevel >= level && window.siyuan.menus.menu.element.dataset.from.includes("popover")) {
if (menuLevel && menuLevel >= level && window.siyuan.menus.menu.element.dataset.from?.includes("popover")) {

Copilot uses AI. Check for mistakes.
// https://github.com/siyuan-note/siyuan/issues/9854 右键菜单不是从浮窗中弹出的则不进行移除
window.siyuan.menus.menu.remove();
}
Expand Down
8 changes: 5 additions & 3 deletions app/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"; // 大纲标题右键菜单
Expand Down
2 changes: 1 addition & 1 deletion app/src/menus/Menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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; // 移除数据
}

Expand Down
4 changes: 4 additions & 0 deletions app/src/menus/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {openByMobile} from "../protyle/util/compatibility";
import {addFilesToDatabase} from "../protyle/render/av/addToDatabase";

const initMultiMenu = (selectItemElements: NodeListOf<Element>, 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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
};

Expand Down
2 changes: 1 addition & 1 deletion app/src/protyle/breadcrumb/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions app/src/protyle/header/Title.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,15 @@ 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) => {
if (event.shiftKey) {
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");
Expand Down
6 changes: 3 additions & 3 deletions app/src/protyle/header/openTitleMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
Expand Down Expand Up @@ -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");
});
};