From 31c8a6542b193f48a8ece550fc4421834018e862 Mon Sep 17 00:00:00 2001 From: TPOB <19909103+TTTPOB@users.noreply.github.com> Date: Tue, 6 Jan 2026 23:04:52 +0800 Subject: [PATCH] fix: table copy (#16783) Co-authored-by: tpob --- app/src/protyle/wysiwyg/index.ts | 34 +++++++++++++++----------------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts index dc3f1b51f..d1f742bae 100644 --- a/app/src/protyle/wysiwyg/index.ts +++ b/app/src/protyle/wysiwyg/index.ts @@ -381,29 +381,27 @@ export class WYSIWYG { html = html.substring(0, html.length - 1) + "]"; } } else if (selectTableElement) { - const selectCellElements: HTMLTableCellElement[] = []; const scrollLeft = nodeElement.firstElementChild.scrollLeft; const scrollTop = nodeElement.querySelector("table").scrollTop; const tableSelectElement = nodeElement.querySelector(".table__select") as HTMLElement; html = ""; - nodeElement.querySelectorAll("th, td").forEach((item: HTMLTableCellElement) => { - if (!item.classList.contains("fn__none") && isIncludeCell({ - tableSelectElement, - scrollLeft, - scrollTop, - item, - })) { - selectCellElements.push(item); - } - }); - selectCellElements.forEach((item, index) => { - if (index === 0 || !item.previousElementSibling || - item.previousElementSibling !== selectCellElements[index - 1]) { + nodeElement.querySelectorAll("tr").forEach(rowElement => { + const rowCells: HTMLTableCellElement[] = []; + rowElement.querySelectorAll("th, td").forEach((item: HTMLTableCellElement) => { + if (!item.classList.contains("fn__none") && isIncludeCell({ + tableSelectElement, + scrollLeft, + scrollTop, + item, + })) { + rowCells.push(item); + } + }); + if (rowCells.length > 0) { html += ""; - } - html += item.outerHTML; - if (!item.nextElementSibling || !selectCellElements[index + 1] || - item.nextElementSibling !== selectCellElements[index + 1]) { + rowCells.forEach(cell => { + html += cell.outerHTML; + }); html += ""; } });