From 84cae3102166ffc34078ce3fbc034afe2c2025f7 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Sat, 13 Jun 2026 10:52:12 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/16869 --- app/src/menus/protyle.ts | 10 ++++++++++ app/src/protyle/util/selection.ts | 6 ++++++ app/src/protyle/util/table.ts | 6 ++++++ 3 files changed, 22 insertions(+) diff --git a/app/src/menus/protyle.ts b/app/src/menus/protyle.ts index 0287738aa..ca0cd3f9c 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 6945a2d65..6b982d3ab 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 402fd104d..4c1cf55e3 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;