diff --git a/app/src/protyle/util/selection.ts b/app/src/protyle/util/selection.ts
index 23086aa5c..9fedb55ed 100644
--- a/app/src/protyle/util/selection.ts
+++ b/app/src/protyle/util/selection.ts
@@ -417,7 +417,7 @@ export const focusByOffset = (container: Element, start: number, end: number, is
} else if (isFocus && (isNotEditBlock(container) || container.classList.contains("av"))) {
return focusBlock(container);
}
- let startNode;
+ let startNode: Node;
searchNode(container, container.firstChild, node => {
if (node.nodeType === Node.TEXT_NODE) {
const dataLength = (node as Text).data.length;
@@ -428,6 +428,14 @@ export const focusByOffset = (container: Element, start: number, end: number, is
start -= dataLength;
end -= dataLength;
return false;
+ } else if (node.nodeType === Node.ELEMENT_NODE && (node as Element).tagName === "BR") {
+ if (start <= 1) {
+ startNode = node;
+ return true;
+ }
+ start -= 1;
+ end -= 1;
+ return false;
}
});
@@ -448,7 +456,7 @@ export const focusByOffset = (container: Element, start: number, end: number, is
const range = document.createRange();
if (startNode) {
- if (start < (startNode as Text).data.length) {
+ if (startNode.nodeType === Node.TEXT_NODE && start < (startNode as Text).data.length) {
range.setStart(startNode, start);
} else {
range.setStartAfter(startNode);
diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts
index 749ada062..8ccff2fbc 100644
--- a/app/src/protyle/wysiwyg/index.ts
+++ b/app/src/protyle/wysiwyg/index.ts
@@ -422,6 +422,9 @@ export class WYSIWYG {
if (isEndOfBlock(range)) {
textPlain = textPlain.replace(/\n$/, "");
}
+ } else if (hasClosestByTag(range.startContainer, "TD") || hasClosestByTag(range.startContainer, "TH")) {
+ tempElement.innerHTML = tempElement.innerHTML.replace(/
/g, "\n").replace(/
/g, "\n");
+ textPlain = tempElement.textContent;
} else if (!hasClosestByTag(range.startContainer, "CODE")) {
textPlain = range.toString();
}
@@ -1678,6 +1681,9 @@ export class WYSIWYG {
protyle.hint.render(protyle);
if (!selectAVElement) {
textPlain = textPlain || protyle.lute.BlockDOM2StdMd(html).trimEnd(); // 需要 trimEnd,否则 \n 会导致 https://github.com/siyuan-note/siyuan/issues/6218
+ if (nodeElement.classList.contains("table")) {
+ textPlain = textPlain.replace(/
/g, "\n").replace(/
/g, "\n");
+ }
}
textPlain = textPlain.replace(/\u00A0/g, " "); // Replace non-breaking spaces with normal spaces when copying https://github.com/siyuan-note/siyuan/issues/9382
event.clipboardData.setData("text/plain", textPlain);