diff --git a/app/src/protyle/render/av/render.ts b/app/src/protyle/render/av/render.ts index 7748311c5..73f1c7d45 100644 --- a/app/src/protyle/render/av/render.ts +++ b/app/src/protyle/render/av/render.ts @@ -11,8 +11,9 @@ import {renderAVAttribute} from "./blockAttr"; import {showMessage} from "../../../dialog/message"; import {addClearButton} from "../../../util/addClearButton"; import {escapeAriaLabel, escapeAttr, escapeHtml} from "../../../util/escape"; +import {electronUndo} from "../../undo"; -export const avRender = (element: Element, protyle: IProtyle, cb?: () => void, viewID?: string) => { +export const avRender = (element: Element, protyle: IProtyle, cb?: () => void, viewID?: string, renderAll = true) => { let avElements: Element[] = []; if (element.getAttribute("data-type") === "NodeAttributeView") { // 编辑器内代码块编辑渲染 @@ -209,7 +210,26 @@ ${cell.color ? `color:${cell.color};` : ""}">${renderCell(cell.value, rowIndex)} viewData = item; } }); - e.firstElementChild.outerHTML = `
+ const avBodyHTML = `
+ ${tableHTML} +
+
+ + + +
+
+
${calcHTML}
+
` + if (renderAll) { + e.firstElementChild.outerHTML = `
@@ -257,27 +277,13 @@ ${cell.color ? `color:${cell.color};` : ""}">${renderCell(cell.value, rowIndex)}
-
- ${tableHTML} -
-
- - - -
-
-
${calcHTML}
-
+ ${avBodyHTML}
${Constants.ZWSP}
`; + } else { + e.firstElementChild.querySelector(".av__scroll").innerHTML = avBodyHTML; + } e.setAttribute("data-render", "true"); // 历史兼容 e.style.margin = ""; @@ -343,6 +349,9 @@ ${cell.color ? `color:${cell.color};` : ""}">${renderCell(cell.value, rowIndex)} if (cb) { cb(); } + if (!renderAll) { + return; + } const viewsElement = e.querySelector(".av__views") as HTMLElement; searchInputElement = e.querySelector('[data-type="av-search"]') as HTMLInputElement; searchInputElement.value = query || ""; @@ -352,6 +361,12 @@ ${cell.color ? `color:${cell.color};` : ""}">${renderCell(cell.value, rowIndex)} searchInputElement.addEventListener("compositionstart", (event: KeyboardEvent) => { event.stopPropagation(); }); + searchInputElement.addEventListener("keydown", (event: KeyboardEvent) => { + if (event.isComposing) { + return; + } + electronUndo(event); + }); searchInputElement.addEventListener("input", (event: KeyboardEvent) => { event.stopPropagation(); if (event.isComposing) { @@ -403,7 +418,7 @@ const updateSearch = (e: HTMLElement, protyle: IProtyle) => { clearTimeout(searchTimeout); searchTimeout = window.setTimeout(() => { e.removeAttribute("data-render"); - avRender(e, protyle); + avRender(e, protyle, undefined, undefined, false); }, Constants.TIMEOUT_INPUT); }; diff --git a/app/src/protyle/util/insertHTML.ts b/app/src/protyle/util/insertHTML.ts index b8ccb80d1..d6447647c 100644 --- a/app/src/protyle/util/insertHTML.ts +++ b/app/src/protyle/util/insertHTML.ts @@ -193,11 +193,11 @@ const processAV = (range: Range, html: string, protyle: IProtyle, blockElement: text.split("\n").forEach(row => { textJSON.push(row.split("\t")); }); - if (rowsElement && textJSON.length === 1 && textJSON[0].length === 1) { + if (rowsElement.length > 0 && textJSON.length === 1 && textJSON[0].length === 1) { updateCellsValue(protyle, blockElement as HTMLElement, text, undefined, columns, html); return; } - if (rowsElement) { + if (rowsElement.length > 0) { rowsElement.forEach(rowElement => { rowElement.querySelectorAll(".av__cell").forEach((cellElement: HTMLElement) => { cellElements.push(cellElement); diff --git a/app/src/protyle/wysiwyg/transaction.ts b/app/src/protyle/wysiwyg/transaction.ts index 5c8adb8bd..87d37f6e6 100644 --- a/app/src/protyle/wysiwyg/transaction.ts +++ b/app/src/protyle/wysiwyg/transaction.ts @@ -744,7 +744,20 @@ export const onTransaction = (protyle: IProtyle, operation: IOperation, isUndo: "removeAttrViewView", "setAttrViewViewName", "setAttrViewViewIcon", "duplicateAttrViewView", "sortAttrViewView", "updateAttrViewColRelation", "setAttrViewPageSize", "updateAttrViewColRollup", "sortAttrViewKey", "duplicateAttrViewKey", "setAttrViewViewDesc", "setAttrViewColDesc"].includes(operation.action)) { - refreshAV(protyle, operation); + if (!isUndo) { + // 撤销 transaction 会进行推送,需使用推送来进行刷新最新数据 https://github.com/siyuan-note/siyuan/issues/13607 + refreshAV(protyle, operation); + } else if (operation.action === "setAttrViewName") { + // setAttrViewName 同文档不会推送,需手动刷新 + Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-av-id="${operation.id}"]`)).forEach((item: HTMLElement) => { + const titleElement = item.querySelector(".av__title") as HTMLElement; + if (!titleElement) { + return; + } + titleElement.textContent = operation.data; + titleElement.dataset.title = operation.data; + }); + } return; } if (operation.action === "doUpdateUpdated") {