Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: https://github.com/siyuan-note/siyuan/issues/18084

Vanessa62b5fe13a902
diff --git a/app/src/protyle/util/selection.ts b/app/src/protyle/util/selection.ts
index 22e3c16301..652d46bd26 100644
--- a/app/src/protyle/util/selection.ts
+++ b/app/src/protyle/util/selection.ts
@@ -570,16 +570,15 @@ export const setInsertWbrHTML = (nodeElement: HTMLElement, range: Range, protyle
const cellElement = hasClosestByTag(range.startContainer, "TH") || hasClosestByTag(range.startContainer, "TD");
if (cellElement) {
const offset = getSelectionOffset(cellElement, nodeElement, range);
- cellElement.classList.add("range");
const cloneNode = nodeElement.cloneNode(true) as HTMLElement;
- // 仅移除临时打上的 range 标记,保留 fn__none 等单元格原有 class(合并单元格的占位 class 若被清掉会导致多出空格子)
- cellElement.classList.remove("range");
- const cloneCellElement = cloneNode.querySelector(".range");
+ // 通过单元格在行内的索引在克隆树中定位对应单元格,避免在原 DOM 上增删 class 残留 class="" https://github.com/siyuan-note/siyuan/issues/18084
+ const cellIndex = Array.from(cellElement.parentElement.children).indexOf(cellElement);
+ const rowIndex = Array.from(nodeElement.querySelector("table").rows).indexOf(cellElement.parentElement as HTMLTableRowElement);
+ const cloneCellElement = cloneNode.querySelector("table").rows[rowIndex].cells[cellIndex];
const cloneRange = focusByOffset(cloneCellElement, offset.end, offset.end, false);
if (cloneRange) {
cloneRange.insertNode(document.createElement("wbr"));
}
- cloneCellElement.classList.remove("range");
protyle.wysiwyg.lastHTMLs[nodeElement.getAttribute("data-node-id")] = cloneNode.outerHTML;
}
} else {
diff --git a/app/src/protyle/util/table.ts b/app/src/protyle/util/table.ts
index 17c73bb902..ba22d3a7ad 100644
--- a/app/src/protyle/util/table.ts
+++ b/app/src/protyle/util/table.ts
@@ -132,11 +132,9 @@ export const insertRowAbove = (protyle: IProtyle, range: Range, cellElement: HTM
hasNone = true;
}
// 不需要空格,否则列宽调整后在空格后插入图片会换行 https://github.com/siyuan-note/siyuan/issues/7631
- if (cellElement.tagName === "TH") {
- rowHTML += `<th class="${currentCellElement.className}" colspan="${currentCellElement.colSpan}" align="${currentCellElement.getAttribute("align")}"></th>`;
- } else {
- rowHTML += `<td class="${currentCellElement.className}" colspan="${currentCellElement.colSpan}" align="${currentCellElement.getAttribute("align")}"></td>`;
- }
+ const classAttr = className ? ` class="${className}"` : "";
+ const tag = cellElement.tagName === "TH" ? "th" : "td";
+ rowHTML += `<${tag}${classAttr} colspan="${currentCellElement.colSpan}" align="${currentCellElement.getAttribute("align") || ""}"></${tag}>`;
}
if (hasNone) {