mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-02 09:40:16 +08:00
This commit is contained in:
parent
9889ef7fb2
commit
84e59e83f5
@ -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);
|
||||
|
@ -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(/<br>/g, "\n").replace(/<br\/>/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(/<br>/g, "\n").replace(/<br\/>/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);
|
||||
|
Loading…
Reference in New Issue
Block a user