From 5546bb75b84f312d62e24f3ea71e9efb81fb8c19 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Fri, 14 Jul 2023 00:41:49 +0800 Subject: [PATCH] :sparkles: https://github.com/siyuan-note/siyuan/issues/8664 --- app/src/protyle/render/av/select.ts | 58 +++++++++++++---------------- 1 file changed, 26 insertions(+), 32 deletions(-) diff --git a/app/src/protyle/render/av/select.ts b/app/src/protyle/render/av/select.ts index 3df4a65e8..7aa900e52 100644 --- a/app/src/protyle/render/av/select.ts +++ b/app/src/protyle/render/av/select.ts @@ -355,7 +355,13 @@ export const addSelectColAndCell = (protyle: IProtyle, data: IAV, options: { }, currentElement: HTMLElement, menuElement: HTMLElement) => { const rowID = options.cellElement.parentElement.dataset.id; const colId = options.cellElement.dataset.colId; - const cellId = options.cellElement.dataset.id; + let cellIndex = 0; + Array.from(options.cellElement.parentElement.querySelectorAll(".av__cell")).find((item: HTMLElement, index) => { + if (item.dataset.id === options.cellElement.dataset.id) { + cellIndex = index; + return true; + } + }) let colData: IAVColumn; data.view.columns.find((item: IAVColumn) => { if (item.id === colId) { @@ -369,38 +375,26 @@ export const addSelectColAndCell = (protyle: IProtyle, data: IAV, options: { let cellData: IAVCell; data.view.rows.find(row => { if (row.id === rowID) { - row.cells.find(cell => { - if (cell.id === cellId) { - cellData = cell; - if (!cellData.value.mSelect) { - cellData.value.mSelect = []; - } - return true; - } - }); + cellData = row.cells[cellIndex]; + // 为空时 cellId 每次请求都不一致 + cellData.id = options.cellElement.dataset.id; + if (!cellData.value) { + cellData.value = {mSelect:[]} as IAVCellValue; + } return true; } }); - if (!cellData) { - cellData = { - color: "", - bgColor: "", - id: Lute.NewNodeID(), - value: genCellValue(colData.type, ""), - valueType: colData.type - }; - } else { - let hasSelected = false; - cellData.value.mSelect.find((item) => { - if (item.content === currentElement.dataset.name) { - hasSelected = true; - return true; - } - }); - if (hasSelected) { - menuElement.querySelector("input").focus(); - return; + + let hasSelected = false; + cellData.value.mSelect.find((item) => { + if (item.content === currentElement.dataset.name) { + hasSelected = true; + return true; } + }); + if (hasSelected) { + menuElement.querySelector("input").focus(); + return; } const oldValue = Object.assign([], cellData.value.mSelect); @@ -428,7 +422,7 @@ export const addSelectColAndCell = (protyle: IProtyle, data: IAV, options: { data: colData.options }, { action: "updateAttrViewCell", - id: cellId, + id: cellData.id, keyID: colId, rowID, avID: data.id, @@ -442,14 +436,14 @@ export const addSelectColAndCell = (protyle: IProtyle, data: IAV, options: { } else { transaction(protyle, [{ action: "updateAttrViewCell", - id: cellId, + id: cellData.id, keyID: colId, rowID, avID: data.id, data: cellData.value }], [{ action: "updateAttrViewCell", - id: cellId, + id: cellData.id, keyID: colId, rowID, avID: data.id,