fix: layout bug when collection search is open

This commit is contained in:
windingwind 2024-02-24 19:59:02 +08:00
parent 44524014d2
commit d5aa38cb79
2 changed files with 20 additions and 3 deletions

View File

@ -58,7 +58,7 @@
"unist-util-visit": "^5.0.0",
"unist-util-visit-parents": "^6.0.1",
"yamljs": "^0.3.0",
"zotero-plugin-toolkit": "^2.3.15"
"zotero-plugin-toolkit": "^2.3.22"
},
"devDependencies": {
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",

View File

@ -15,7 +15,7 @@ export function registerWorkspaceTab(win: Window) {
if (!spacer) {
return;
}
ztoolkit.UI.insertElementBefore(
const tabButton = ztoolkit.UI.insertElementBefore(
{
tag: "toolbarbutton",
classList: ["zotero-tb-button"],
@ -39,8 +39,25 @@ export function registerWorkspaceTab(win: Window) {
],
},
spacer,
) as XUL.ToolBarButton;
win.addEventListener("message", messageHandler, false);
const collectionSearch = doc.querySelector("#zotero-collections-search")!;
const ob = new (ztoolkit.getGlobal("MutationObserver"))((muts) => {
tabButton.hidden = !!collectionSearch?.classList.contains("visible");
});
ob.observe(collectionSearch, {
attributes: true,
attributeFilter: ["class"],
});
win.addEventListener(
"unload",
() => {
ob.disconnect();
win.removeEventListener("message", messageHandler);
},
{ once: true },
);
win.addEventListener("message", (e) => messageHandler(e), false);
}
export async function openWorkspaceTab() {