From 70b23c351fb066adf58c27df161faf6fa30d884a Mon Sep 17 00:00:00 2001 From: Vanessa Date: Fri, 20 Feb 2026 14:15:26 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/17051 --- app/src/menus/protyle.ts | 6 +++--- app/src/protyle/util/table.ts | 7 +++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/src/menus/protyle.ts b/app/src/menus/protyle.ts index 0ec84e72c..7b3233d97 100644 --- a/app/src/menus/protyle.ts +++ b/app/src/menus/protyle.ts @@ -2261,7 +2261,7 @@ export const tableMenu = (protyle: IProtyle, nodeElement: Element, cellElement: const location = (dialog.element.querySelector("select") as HTMLSelectElement).value; const captionElement = nodeElement.querySelector("caption"); if (title) { - const html = `${Lute.EscapeHTMLStr(title)}`; + const html = `${Lute.EscapeHTMLStr(title)}`; if (captionElement) { captionElement.outerHTML = html; } else { @@ -2400,8 +2400,8 @@ export const tableMenu = (protyle: IProtyle, nodeElement: Element, cellElement: ${window.siyuan.languages.insertRowBefore.replace("${x}", ``)} `, accelerator: window.siyuan.config.keymap.editor.table.insertRowAbove.custom, - click: () => { - insertRowAbove(protyle, range, cellElement, nodeElement); + click: (element: HTMLElement) => { + insertRowAbove(protyle, range, cellElement, nodeElement, parseInt(element.querySelector("input").value)); } }); if (!nextHasNone || (nextHasNone && !nextHasRowSpan && nextHasColSpan)) { diff --git a/app/src/protyle/util/table.ts b/app/src/protyle/util/table.ts index 5349ace36..9dd58bf47 100644 --- a/app/src/protyle/util/table.ts +++ b/app/src/protyle/util/table.ts @@ -121,7 +121,7 @@ export const insertRow = (protyle: IProtyle, range: Range, cellElement: HTMLElem scrollToView(nodeElement, newRowElememt, protyle); }; -export const insertRowAbove = (protyle: IProtyle, range: Range, cellElement: HTMLElement, nodeElement: Element) => { +export const insertRowAbove = (protyle: IProtyle, range: Range, cellElement: HTMLElement, nodeElement: Element, count = 1) => { const wbrElement = document.createElement("wbr"); range.insertNode(wbrElement); const html = nodeElement.outerHTML; @@ -160,10 +160,13 @@ export const insertRowAbove = (protyle: IProtyle, range: Range, cellElement: HTM if (cellElement.parentElement.parentElement.tagName === "THEAD" && !cellElement.parentElement.previousElementSibling) { cellElement.parentElement.parentElement.insertAdjacentHTML("beforebegin", `${rowHTML}`); newRowElememt = nodeElement.querySelector("thead tr"); + if (count > 1) { + cellElement.parentElement.parentElement.nextElementSibling.insertAdjacentHTML("afterbegin", `${rowHTML.replace(//g, "")}`.repeat(count - 1)); + } cellElement.parentElement.parentElement.nextElementSibling.insertAdjacentHTML("afterbegin", cellElement.parentElement.parentElement.innerHTML.replace(//g, "")); cellElement.parentElement.parentElement.remove(); } else { - cellElement.parentElement.insertAdjacentHTML("beforebegin", `${rowHTML}`); + cellElement.parentElement.insertAdjacentHTML("beforebegin", `${rowHTML}`.repeat(count)); newRowElememt = cellElement.parentElement.previousElementSibling as HTMLTableRowElement; } range.selectNodeContents(newRowElememt.cells[getColIndex(cellElement)]);