From 3464708aaeb746a84d1559aa42565660aa307d62 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Tue, 25 Feb 2025 23:48:53 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/pull/14182 --- app/src/menus/Menu.ts | 13 +++---------- app/src/plugin/Menu.ts | 28 +++++++++++++++++++--------- app/src/protyle/render/av/action.ts | 4 ++-- app/src/protyle/render/av/asset.ts | 6 +++--- app/src/protyle/render/av/col.ts | 6 +++--- 5 files changed, 30 insertions(+), 27 deletions(-) diff --git a/app/src/menus/Menu.ts b/app/src/menus/Menu.ts index d075cd56d..74057e832 100644 --- a/app/src/menus/Menu.ts +++ b/app/src/menus/Menu.ts @@ -84,13 +84,6 @@ export class Menu { } } - public addSeparator(index?: number, id?: string) { - if (id) { - return this.addItem({id: "separator_" + id, type: "separator", index}); - } - return this.addItem({type: "separator", index}); - } - public addItem(option: IMenu) { const menuItem = new MenuItem(option); this.append(menuItem.element, option.index); @@ -384,11 +377,11 @@ export class subMenu { this.menus = []; } - addSeparator(index?: number) { + addSeparator(index?: number, id?: string) { if (typeof index === "number") { - this.menus.splice(index, 0, {type: "separator"}); + this.menus.splice(index, 0, {type: "separator", id}); } else { - this.menus.push({type: "separator"}); + this.menus.push({type: "separator", id}); } } diff --git a/app/src/plugin/Menu.ts b/app/src/plugin/Menu.ts index cc8db5e34..0eb1bb74f 100644 --- a/app/src/plugin/Menu.ts +++ b/app/src/plugin/Menu.ts @@ -34,17 +34,27 @@ export class Menu { return this.menu.addItem(option); } - addSeparator(index?: number, ignore = false, id?: string) { - if (ignore) { + addSeparator(options?: number | { + index?: number, + id?: string, + ignore?: boolean + }, ignoreParam = false) { + // 兼容 3.1.24 之前的版本 addSeparator(index?: number, ignore?: boolean): HTMLElement; + let id: string; + let index: number; + let ignore = false; + if (typeof options === "object") { + ignore = options.ignore || false; + index = options.index; + id = options.id; + } else if (typeof options === "number") { + index = options; + ignore = ignoreParam; + } + if (ignore || this.isOpen) { return; } - if (this.isOpen) { - return; - } - if (id) { - return this.menu.addSeparator(index, id); - } - return this.menu.addSeparator(index); + return this.menu.addItem({id, type: "separator", index}); } open(options: IPosition) { diff --git a/app/src/protyle/render/av/action.ts b/app/src/protyle/render/av/action.ts index 3b985ceec..472f9f2f5 100644 --- a/app/src/protyle/render/av/action.ts +++ b/app/src/protyle/render/av/action.ts @@ -522,7 +522,7 @@ export const avContextmenu = (protyle: IProtyle, rowElement: HTMLElement, positi }); if (rowElements.length === 1) { if (keyCellElement.getAttribute("data-detached") !== "true") { - menu.addSeparator(undefined, undefined, "1"); + menu.addSeparator({id: "separator_1"}); } menu.addItem({ id: "insertRowBefore", @@ -570,7 +570,7 @@ ${window.siyuan.languages.insertRowAfter.replace("${x}", ` 0) { - menu.addSeparator(undefined, undefined, "2"); + menu.addSeparator({id: "separator_2"}); } if (type !== "file") { menu.addItem({ diff --git a/app/src/protyle/render/av/col.ts b/app/src/protyle/render/av/col.ts index 138056040..8a8f426fb 100644 --- a/app/src/protyle/render/av/col.ts +++ b/app/src/protyle/render/av/col.ts @@ -761,7 +761,7 @@ export const showColMenu = (protyle: IProtyle, blockElement: Element, cellElemen }); } }); - menu.addSeparator(undefined, undefined, "1"); + menu.addSeparator({id: "separator_1"}); // 行号 类型不参与 排序和筛选 if (type !== "lineNumber") { @@ -851,7 +851,7 @@ export const showColMenu = (protyle: IProtyle, blockElement: Element, cellElemen } }); } - menu.addSeparator(undefined, undefined, "2"); + menu.addSeparator({id: "separator_2"}); } menu.addItem({ id: "insertColumnLeft", @@ -1034,7 +1034,7 @@ export const showColMenu = (protyle: IProtyle, blockElement: Element, cellElemen }); } }); - menu.addSeparator(undefined, undefined, "3"); + menu.addSeparator({id: "separator_3"}); } menu.addItem({ id: "wrap",