An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Synchronize resized table columns across embedded copies https://github.com/siyuan-note/siyuan/issues/20773
Daniel74e4f344288b
diff --git a/app/src/protyle/render/tableCellInput.test.ts b/app/src/protyle/render/tableCellInput.test.tsindex e745521b91..00d71f454b 100644--- a/app/src/protyle/render/tableCellInput.test.ts+++ b/app/src/protyle/render/tableCellInput.test.ts@@ -191,7 +191,10 @@ const browserCases = async (source: string, queueSource: string, editorSource: scleanListMindmapHTML: (html: string) => html, cleanHeadingNumberHTML: (html: string) => html,cleanBlockSelectionModeHTML: (html: string) => html,getVisibleFoldHeadingHTML: (html: string) => { snapshotParses++; return html; },- getEmbedChildOperationContext: noop,+ getEmbedChildOperationContext: (element: Element) => {+ const resultElement = element.closest?.(".protyle-wysiwyg__embed");+ return resultElement ? {resultElement} : undefined;+ },isInEmbedBlock: (element: Element) => element.closest(".protyle-wysiwyg__embed"),captureBlockSelectionModeState: noop, restoreBlockSelectionModeState: noop,disposeCustomBlocksInElement: noop, processRender: noop, highlightRender: noop,@@ -479,6 +482,34 @@ const browserCases = async (source: string, queueSource: string, editorSource: s}// 执行外层编辑器的完整鼠标监听器,区分单元格点击与真正的跨单元格拖选。+ for (const editEmbedded of [false, true]) {+ const {owner, element, wysiwyg, table} = fixture();+ const embed = document.createElement("div");+ embed.className = "protyle-wysiwyg__embed";+ embed.dataset.id = table.dataset.nodeId;+ embed.innerHTML = table.outerHTML;+ wysiwyg.appendChild(embed);+ const embedded = embed.querySelector<HTMLElement>('[data-type="NodeTable"]');+ const source = editEmbedded ? embedded : table;+ const other = editEmbedded ? table : embedded;+ const range = document.createRange();+ range.selectNodeContents(other.querySelector("th"));+ range.collapse(true);+ getSelection().removeAllRanges();+ getSelection().addRange(range);+ source.querySelector<HTMLElement>("col").style.width = "180px";+ source.setAttribute("data-editing", "true");+ transactionAPI.promiseTransaction({protyle: owner, doOperations: [{+ action: "update", id: source.dataset.nodeId, data: api.getTableBlockHTML(source),+ }]});+ check.ok(source.isConnected, "column resizing preserves the explicitly edited occurrence");+ check.equal(source.querySelector<HTMLElement>("col").style.width, "180px");+ check.equal(other.isConnected, false, "a stale text selection must not prevent the other occurrence from refreshing");+ check.equal(wysiwyg.querySelectorAll('[data-type="NodeTable"] col[style*="180px"]').length, 2,+ "source and embedded column widths synchronize in both directions");+ element.remove();+ }+for (const mobile of [false, true]) {const {owner, element, wysiwyg, table} = fixture();const absent = () => false;@@ -660,6 +691,7 @@ const browserCases = async (source: string, queueSource: string, editorSource: s{const {owner, element, wysiwyg, table} = fixture();+ snapshotParses = 0;await open(owner, table.querySelector("th"));const host = table.querySelector(".table__cell-editor");const operation = {action: "update", id: table.dataset.nodeId, data: api.getTableBlockHTML(table)};diff --git a/app/src/protyle/wysiwyg/transaction.ts b/app/src/protyle/wysiwyg/transaction.tsindex 95edac8019..cc06c5e1b6 100644--- a/app/src/protyle/wysiwyg/transaction.ts+++ b/app/src/protyle/wysiwyg/transaction.ts@@ -290,7 +290,8 @@ const promiseTransaction = (options: {);// updateTransaction 会在本地编辑元素上设置该属性,用于在存在同 ID 副本时保留当前 DOM 和光标。const currentUpdateElement = updateElements.find(item =>- item.getAttribute(Constants.ATTRIBUTE_EDITING) === "true" && getEmbedChildOperationContext(item));+ item.getAttribute(Constants.ATTRIBUTE_EDITING) === "true" && getEmbedChildOperationContext(item)) ||+ updateElements.find(item => item.getAttribute(Constants.ATTRIBUTE_EDITING) === "true");const currentEmbedContext = currentUpdateElement && getEmbedChildOperationContext(currentUpdateElement);const currentEmbedElement = currentEmbedContext && isInEmbedBlock(currentUpdateElement, false);@@ -321,9 +322,10 @@ const promiseTransaction = (options: {};let allTempElement: HTMLTemplateElement;+ // 拖拽列宽等操作不移动文本选区,存在明确编辑标记时不能用旧选区保护其他副本。updateElements.forEach((item) => {if ((currentEmbedElement && isInEmbedBlock(item, false) === currentEmbedElement) ||- (range && (item === range.startContainer || item.contains(range.startContainer)))) {+ (!currentUpdateElement && range && (item === range.startContainer || item.contains(range.startContainer)))) {// 正在编辑的块不能进行更新item.removeAttribute(Constants.ATTRIBUTE_EDITING);} else {@@ -333,7 +335,7 @@ const promiseTransaction = (options: {});protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg__embed").forEach(item => {if (item === currentEmbedContext?.resultElement ||- (range && (item === range.startContainer || item.contains(range.startContainer)))) {+ (!currentUpdateElement && range && (item === range.startContainer || item.contains(range.startContainer)))) {// 正在编辑的块不能进行更新item.removeAttribute(Constants.ATTRIBUTE_EDITING);} else {