diff --git a/app/src/menus/index.ts b/app/src/menus/index.ts index dd7191094..5caee18de 100644 --- a/app/src/menus/index.ts +++ b/app/src/menus/index.ts @@ -7,7 +7,7 @@ import {initNavigationMenu, initFileMenu} from "./navigation"; import {initTabMenu} from "./tab"; /// #endif import {Menu} from "./Menu"; -import {hasTopClosestByTag} from "../protyle/util/hasClosest"; +import {hasClosestByClassName, hasTopClosestByTag} from "../protyle/util/hasClosest"; import {App} from "../index"; @@ -73,6 +73,12 @@ export class Menus { break; } + if (hasClosestByClassName(target, "av__panel") && !hasClosestByClassName(target, "b3-menu")) { + document.querySelector(".av__panel").dispatchEvent(new CustomEvent("click", {detail: "close"})) + event.stopPropagation(); + break; + } + target = target.parentElement; } }, false); diff --git a/app/src/protyle/render/av/cell.ts b/app/src/protyle/render/av/cell.ts index 7f8689f28..fae6b21ae 100644 --- a/app/src/protyle/render/av/cell.ts +++ b/app/src/protyle/render/av/cell.ts @@ -439,12 +439,19 @@ export const popTextCell = (protyle: IProtyle, cellElements: HTMLElement[], type } }); } - avMaskElement.addEventListener("click", (event) => { + + const removeAvMask = (event: Event) => { if ((event.target as HTMLElement).classList.contains("av__mask") && document.activeElement.tagName !== "TEXTAREA" && document.activeElement.tagName !== "INPUT") { updateCellValueByInput(protyle, type, blockElement, cellElements); avMaskElement?.remove(); } + } + avMaskElement.addEventListener("click", (event) => { + removeAvMask(event) + }); + avMaskElement.addEventListener("contextmenu", (event) => { + removeAvMask(event) }); }; diff --git a/app/src/protyle/render/av/openMenuPanel.ts b/app/src/protyle/render/av/openMenuPanel.ts index 11a04b11c..50034dd9e 100644 --- a/app/src/protyle/render/av/openMenuPanel.ts +++ b/app/src/protyle/render/av/openMenuPanel.ts @@ -456,10 +456,14 @@ export const openMenuPanel = (options: { window.siyuan.dragElement = undefined; } }); - avPanelElement.addEventListener("click", (event) => { + avPanelElement.addEventListener("click", (event: MouseEvent) => { + let type: string; + if (typeof event.detail === "string") { + type = event.detail; + } let target = event.target as HTMLElement; - while (target && !target.isSameNode(avPanelElement)) { - const type = target.dataset.type; + while (target && !target.isSameNode(avPanelElement) || type) { + type = target.dataset.type || type; if (type === "close") { if (!options.protyle.toolbar.subElement.classList.contains("fn__none")) { // 优先关闭资源文件搜索 @@ -480,6 +484,7 @@ export const openMenuPanel = (options: { menuElement.innerHTML = getViewHTML(data.view); setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height); bindViewEvent({protyle: options.protyle, data, menuElement, blockElement: options.blockElement}); + window.siyuan.menus.menu.remove(); event.preventDefault(); event.stopPropagation(); break; @@ -488,6 +493,7 @@ export const openMenuPanel = (options: { tabRect = options.blockElement.querySelector(".av__views").getBoundingClientRect(); menuElement.innerHTML = getPropertiesHTML(data.view); setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height); + window.siyuan.menus.menu.remove(); event.preventDefault(); event.stopPropagation(); break; @@ -495,6 +501,7 @@ export const openMenuPanel = (options: { menuElement.innerHTML = getSortsHTML(data.view.columns, data.view.sorts); bindSortsEvent(options.protyle, menuElement, data, blockID); setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height); + window.siyuan.menus.menu.remove(); event.preventDefault(); event.stopPropagation(); break; @@ -558,6 +565,7 @@ export const openMenuPanel = (options: { } else if (type === "goFilters") { menuElement.innerHTML = getFiltersHTML(data.view); setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height); + window.siyuan.menus.menu.remove(); event.preventDefault(); event.stopPropagation(); break;