Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: https://github.com/siyuan-note/siyuan/issues/5066 add index for menu

Vanessa19dd0cd796f9
diff --git a/app/src/asset/index.ts b/app/src/asset/index.ts
index e065411009..7448c0f1f5 100644
--- a/app/src/asset/index.ts
+++ b/app/src/asset/index.ts
@@ -33,7 +33,7 @@ export class Asset extends Model {
this.element.addEventListener("click", (event) => {
setPanelFocus(this.element.parentElement.parentElement);
this.app.plugins.forEach(item => {
- item.eventBus.emit("click-pdf", event);
+ item.eventBus.emit("click-pdf", {event});
});
});
if (typeof this.pdfId === "string") {
diff --git a/app/src/menus/Menu.ts b/app/src/menus/Menu.ts
index c13b0a8985..7400afe9d3 100644
--- a/app/src/menus/Menu.ts
+++ b/app/src/menus/Menu.ts
@@ -82,13 +82,13 @@ export class Menu {
}
}
- public addSeparator() {
- this.addItem({type: "separator"});
+ public addSeparator(index?: number) {
+ this.addItem({type: "separator", index});
}
public addItem(option: IMenu) {
const menuItem = new MenuItem(option);
- this.append(menuItem.element);
+ this.append(menuItem.element, option.index);
return menuItem.element;
}
@@ -111,10 +111,17 @@ export class Menu {
window.siyuan.menus.menu.element.removeAttribute("data-name"); // 标识再次点击不消失
}
- public append(element?: HTMLElement) {
+ public append(element?: HTMLElement, index?: number) {
if (!element) {
return;
}
+ if (typeof index === "number") {
+ const insertElement = this.element.querySelectorAll(".b3-menu__items > .b3-menu__separator")[index]
+ if (insertElement) {
+ insertElement.before(element);
+ return;
+ }
+ }
this.element.lastElementChild.append(element);
}
diff --git a/app/src/plugin/API.ts b/app/src/plugin/API.ts
index dea1d7dca2..e3ce0f3cf0 100644
--- a/app/src/plugin/API.ts
+++ b/app/src/plugin/API.ts
@@ -2,7 +2,6 @@ import {confirmDialog} from "../dialog/confirmDialog";
import {Plugin} from "./index";
import {showMessage} from "../dialog/message";
import {Dialog} from "../dialog";
-import {MenuItem} from "../menus/Menu";
import {Menu as SiyuanMenu} from "../menus/Menu";
import {fetchGet, fetchPost, fetchSyncPost} from "../util/fetch";
import {isMobile} from "../util/functions";
@@ -42,11 +41,11 @@ export class Menu {
return this.menu.addItem(option);
}
- addSeparator() {
+ addSeparator(index?: number) {
if (this.isOpen) {
return;
}
- this.menu.addSeparator();
+ this.menu.addSeparator(index);
}
open(options: { x: number, y: number, h?: number, w?: number, isLeft: false }) {
diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.ts
index f57d75b6a9..0abd8079ba 100644
--- a/app/src/types/index.d.ts
+++ b/app/src/types/index.d.ts
@@ -724,6 +724,7 @@ declare interface IMenu {
iconHTML?: string
current?: boolean
bind?: (element: HTMLElement) => void
+ index?: number
}
declare interface IBazaarItem {