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/16869

Vanessa84cae3102166
diff --git a/app/src/menus/protyle.ts b/app/src/menus/protyle.ts
index 0287738aa3..ca0cd3f9ce 100644
--- a/app/src/menus/protyle.ts
+++ b/app/src/menus/protyle.ts
@@ -2190,6 +2190,16 @@ export const tableMenu = (protyle: IProtyle, nodeElement: Element, cellElement:
const tbodyElement = nodeElement.querySelector("tbody");
const theadElement = nodeElement.querySelector("thead");
while (prueTrElement !== theadElement.lastElementChild) {
+ theadElement.lastElementChild.querySelectorAll("th").forEach(item => {
+ const td = document.createElement('td');
+ Array.from(item.attributes).forEach(attr => {
+ td.setAttribute(attr.name, attr.value);
+ });
+ while (item.firstChild) {
+ td.appendChild(item.firstChild);
+ }
+ item.replaceWith(td);
+ });
tbodyElement.insertAdjacentElement("afterbegin", theadElement.lastElementChild);
}
}
diff --git a/app/src/protyle/util/selection.ts b/app/src/protyle/util/selection.ts
index 6945a2d659..6b982d3aba 100644
--- a/app/src/protyle/util/selection.ts
+++ b/app/src/protyle/util/selection.ts
@@ -254,6 +254,9 @@ export const getSelectionPosition = (nodeElement: Element, range?: Range, useDir
let firstNode = range.startContainer.childNodes[range.startOffset] || range.startContainer.firstChild;
while (firstNode) {
if (firstNode.textContent === "" && firstNode.nodeType === 3) {
+ if (!firstNode.previousSibling) {
+ break;
+ }
firstNode = firstNode.previousSibling;
} else {
break;
@@ -265,6 +268,9 @@ export const getSelectionPosition = (nodeElement: Element, range?: Range, useDir
let lastNode = range.startContainer.childNodes[range.startOffset] || range.startContainer.lastChild;
while (lastNode) {
if (lastNode.textContent === "" && lastNode.nodeType === 3) {
+ if (!lastNode.previousSibling) {
+ break;
+ }
lastNode = lastNode.previousSibling;
} else {
break;
diff --git a/app/src/protyle/util/table.ts b/app/src/protyle/util/table.ts
index 402fd104da..4c1cf55e3b 100644
--- a/app/src/protyle/util/table.ts
+++ b/app/src/protyle/util/table.ts
@@ -491,6 +491,9 @@ export const fixTable = (protyle: IProtyle, event: KeyboardEvent, range: Range)
let firstChild = cellElement.firstChild;
while (firstChild) {
if (firstChild.textContent === "" && firstChild.nodeType === 3) {
+ if (!firstChild.nextSibling) {
+ break;
+ }
firstChild = firstChild.nextSibling;
} else {
break;
@@ -525,6 +528,9 @@ export const fixTable = (protyle: IProtyle, event: KeyboardEvent, range: Range)
let lastChild = cellElement.lastChild;
while (lastChild) {
if (lastChild.textContent === "" && lastChild.nodeType === 3) {
+ if (!lastChild.previousSibling) {
+ break;
+ }
lastChild = lastChild.previousSibling;
} else {
break;