From 9d4eef08e94a6aa11c77d4d86ece11448389ba0d Mon Sep 17 00:00:00 2001 From: Vanessa Date: Fri, 13 Sep 2024 22:04:42 +0800 Subject: [PATCH] :bug: fix https://github.com/siyuan-note/siyuan/issues/12006 --- app/src/protyle/render/av/select.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/app/src/protyle/render/av/select.ts b/app/src/protyle/render/av/select.ts index 7ac6f725c..42e40f2aa 100644 --- a/app/src/protyle/render/av/select.ts +++ b/app/src/protyle/render/av/select.ts @@ -179,7 +179,8 @@ export const setColOption = (protyle: IProtyle, data: IAV, target: HTMLElement, } }); const oldScroll = menuElement.querySelector(".b3-menu__items").scrollTop; - const oldChipsHeight = menuElement.querySelector(".b3-chips").clientHeight; + const selectedElement = menuElement.querySelector(".b3-chips") + const oldChipsHeight = selectedElement ? selectedElement.clientHeight : 0; if (!cellElements) { menuElement.innerHTML = getEditHTML({protyle, data, colId, isCustomAttr}); bindEditEvent({protyle, data, menuElement, isCustomAttr, blockID}); @@ -205,13 +206,16 @@ export const setColOption = (protyle: IProtyle, data: IAV, target: HTMLElement, menuElement.innerHTML = getSelectHTML(data.view, cellElements); bindSelectEvent(protyle, data, menuElement, cellElements, blockElement); } - menuElement.querySelector(".b3-menu__items").scrollTop = oldScroll + (menuElement.querySelector(".b3-chips").clientHeight - oldChipsHeight); + if (selectedElement) { + menuElement.querySelector(".b3-menu__items").scrollTop = oldScroll + (menuElement.querySelector(".b3-chips").clientHeight - oldChipsHeight); + } }); if (menu.isOpen) { return; } menu.addItem({ iconHTML: "", + type: "readonly", label: ``, bind(element) { element.querySelector("input").addEventListener("keydown", (event: KeyboardEvent) => { @@ -255,7 +259,8 @@ export const setColOption = (protyle: IProtyle, data: IAV, target: HTMLElement, } }); const oldScroll = menuElement.querySelector(".b3-menu__items").scrollTop; - const oldChipsHeight = menuElement.querySelector(".b3-chips").clientHeight; + const selectedElement = menuElement.querySelector(".b3-chips") + const oldChipsHeight = selectedElement?selectedElement.clientHeight:0; if (!cellElements) { menuElement.innerHTML = getEditHTML({protyle, data, colId, isCustomAttr}); bindEditEvent({protyle, data, menuElement, isCustomAttr, blockID}); @@ -281,7 +286,9 @@ export const setColOption = (protyle: IProtyle, data: IAV, target: HTMLElement, menuElement.innerHTML = getSelectHTML(data.view, cellElements); bindSelectEvent(protyle, data, menuElement, cellElements, blockElement); } - menuElement.querySelector(".b3-menu__items").scrollTop = oldScroll + (menuElement.querySelector(".b3-chips").clientHeight - oldChipsHeight); + if (selectedElement) { + menuElement.querySelector(".b3-menu__items").scrollTop = oldScroll + (menuElement.querySelector(".b3-chips").clientHeight - oldChipsHeight); + } }); } }); @@ -541,7 +548,7 @@ export const addColOptionOrCell = (protyle: IProtyle, data: IAV, cellElements: H menuElement.innerHTML = getSelectHTML(data.view, cellElements); bindSelectEvent(protyle, data, menuElement, cellElements, blockElement); menuElement.querySelector("input").focus(); - menuElement.querySelector(".b3-menu__items").scrollTop = oldScroll + (menuElement.querySelector(".b3-chips").clientHeight - oldChipsHeight); + menuElement.querySelector(".b3-menu__items").scrollTop = oldScroll + (menuElement.querySelector(".b3-chips").clientHeight - oldChipsHeight); } };