mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-23 01:50:12 +01:00
🎨 https://github.com/siyuan-note/siyuan/issues/5066 add index for menu
This commit is contained in:
parent
981c6688b8
commit
19dd0cd796
4 changed files with 15 additions and 8 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue