Skip to content

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

:art: Improve the mobile text selection toolbar by integrating the plugin menu https://github.com/siyuan-note/siyuan/issues/12526

Daniele24829b4debc
diff --git a/app/src/menus/protyle.ts b/app/src/menus/protyle.ts
index aadaee3719..ae6e4be5ae 100644
--- a/app/src/menus/protyle.ts
+++ b/app/src/menus/protyle.ts
@@ -708,9 +708,7 @@ export const contentMenu = (protyle: IProtyle, nodeElement: Element) => {
const range = getEditorRange(nodeElement);
window.siyuan.menus.menu.remove();
window.siyuan.menus.menu.element.setAttribute("data-name", Constants.MENU_INLINE_CONTEXT);
- /// #if MOBILE
- protyle.toolbar.showContent(protyle, range, nodeElement);
- /// #else
+ /// #if !MOBILE
const oldHTML = nodeElement.outerHTML;
const captionElement = hasClosestByTag(range.startContainer, "CAPTION");
if (range.toString() !== "" || (range.cloneContents().childNodes[0] as HTMLElement)?.classList?.contains("emoji")) {
@@ -910,8 +908,9 @@ export const contentMenu = (protyle: IProtyle, nodeElement: Element) => {
}
}
/// #endif
+ let pluginMenus: IMenu[] = [];
if (protyle?.app?.plugins) {
- emitOpenMenu({
+ pluginMenus = emitOpenMenu({
plugins: protyle.app.plugins,
type: "open-menu-content",
detail: {
@@ -920,8 +919,12 @@ export const contentMenu = (protyle: IProtyle, nodeElement: Element) => {
element: nodeElement,
},
separatorPosition: "top",
+ appendToMenu: !isMobile(),
});
}
+ /// #if MOBILE
+ protyle.toolbar.showContent(protyle, range, nodeElement, pluginMenus);
+ /// #endif
};
export const enterBack = (protyle: IProtyle, id: string) => {
diff --git a/app/src/plugin/EventBus.ts b/app/src/plugin/EventBus.ts
index 40ea3f9f80..d21ef133d6 100644
--- a/app/src/plugin/EventBus.ts
+++ b/app/src/plugin/EventBus.ts
@@ -29,13 +29,14 @@ export const emitOpenMenu = (options: {
type: TEventBus,
detail: any,
separatorPosition?: "top" | "bottom",
+ appendToMenu?: boolean,
}) => {
const pluginSubMenu = new subMenu();
options.detail.menu = pluginSubMenu;
options.plugins.forEach((plugin) => {
plugin.eventBus.emit(options.type, options.detail);
});
- if (pluginSubMenu.menus.length > 0) {
+ if (pluginSubMenu.menus.length > 0 && options.appendToMenu !== false) {
if (options.separatorPosition === "top") {
window.siyuan.menus.menu.append(new MenuItem({id: "separator_pluginTop", type: "separator"}).element);
}
@@ -50,4 +51,5 @@ export const emitOpenMenu = (options: {
window.siyuan.menus.menu.append(new MenuItem({id: "separator_pluginBottom", type: "separator"}).element);
}
}
+ return pluginSubMenu.menus;
};
diff --git a/app/src/protyle/toolbar/index.ts b/app/src/protyle/toolbar/index.ts
index 6e78cc66ba..e0fa6fdfb4 100644
--- a/app/src/protyle/toolbar/index.ts
+++ b/app/src/protyle/toolbar/index.ts
@@ -1916,7 +1916,7 @@ export class Toolbar {
genList(true);
}
- public showContent(protyle: IProtyle, range: Range, nodeElement: Element) {
+ public showContent(protyle: IProtyle, range: Range, nodeElement: Element, pluginMenus: IMenu[] = []) {
this.range = range;
hideElements(["hint"], protyle);
this.clearSubElement();
@@ -1935,6 +1935,9 @@ export class Toolbar {
html += `<button class="keyboard__action" data-action="paste"><svg><use xlink:href="#iconPaste"></use></svg></button>
<button class="keyboard__action" data-action="select"><svg><use xlink:href="#iconSelect"></use></svg></button>`;
}
+ if (pluginMenus.length > 0) {
+ html += `<button class="keyboard__action" data-action="plugin" data-menu="true" aria-label="${window.siyuan.languages.plugin}"><svg><use xlink:href="#iconPlugin"></use></svg></button>`;
+ }
if (hasCopy || !protyle.disabled) {
html += '<button class="keyboard__action" data-action="more"><svg><use xlink:href="#iconMore"></use></svg></button>';
}
@@ -1992,6 +1995,17 @@ export class Toolbar {
this.subElement.classList.add("fn__none");
} else if (action === "back") {
this.subElement.lastElementChild.innerHTML = html;
+ } else if (action === "plugin") {
+ window.siyuan.menus.menu.remove();
+ pluginMenus.forEach(item => window.siyuan.menus.menu.addItem({...item, index: undefined}));
+ const triggerRect = btnElemen.getBoundingClientRect();
+ const selectionRect = this.range.getBoundingClientRect();
+ window.siyuan.menus.menu.popup({
+ x: triggerRect.left,
+ y: selectionRect.bottom + 8,
+ h: selectionRect.height + 8,
+ });
+ this.subElement.classList.add("fn__none");
} else if (action === "more") {
this.subElement.lastElementChild.innerHTML = `<button class="keyboard__action${hasCopy ? "" : " fn__none"}" data-action="copyPlainText"><span>${window.siyuan.languages.copyPlainText}</span></button>
<div class="keyboard__split${hasCopy ? "" : " fn__none"}"></div>
diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts
index c1b51e807a..af29426b3c 100644
--- a/app/src/protyle/wysiwyg/index.ts
+++ b/app/src/protyle/wysiwyg/index.ts
@@ -3456,7 +3456,9 @@ export class WYSIWYG {
}
contentMenu(protyle, nodeElement);
addSpellcheckMenuItems(spellcheckContext);
+ /// #if !MOBILE
window.siyuan.menus.menu.popup({x, y: y + 13, h: 26});
+ /// #endif
protyle.toolbar?.element.classList.add("fn__none");
if (nodeElement.classList.contains("table")) {
nodeElement.querySelector(".table__select").removeAttribute("style");