Vanessa 2024-12-30 21:06:26 +08:00
parent a47e5929e7
commit 1f06440442
2 changed files with 23 additions and 21 deletions

View file

@ -541,19 +541,27 @@ const removeEmptyNode = (newElement: Element) => {
export const softEnter = (range: Range, nodeElement: HTMLElement, protyle: IProtyle) => {
let startElement = range.startContainer as HTMLElement;
const nextSibling = hasNextSibling(startElement) as Element;
// 图片之前软换行
if (nextSibling && nextSibling.nodeType !== 3 && nextSibling.classList.contains("img")) {
nextSibling.insertAdjacentHTML("beforebegin", "<wbr>");
const oldHTML = nodeElement.outerHTML;
nextSibling.previousElementSibling.remove();
const newlineNode = document.createTextNode("\n");
startElement.after(document.createTextNode(Constants.ZWSP));
startElement.after(newlineNode);
range.selectNode(newlineNode);
range.collapse(false);
updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, oldHTML);
if (nodeElement.getAttribute("data-type") === "NodeAttributeView") {
return true;
}
if (nextSibling && nextSibling.nodeType !== 3) {
const textPosition = getSelectionOffset(range.startContainer, protyle.wysiwyg.element, range);
if (textPosition.end === range.endContainer.textContent.length) {
// 图片之前软换行 || 数学公式之前软换行 https://github.com/siyuan-note/siyuan/issues/13621
if (nextSibling.classList.contains("img") || nextSibling.getAttribute("data-type") === "inline-math") {
nextSibling.insertAdjacentHTML("beforebegin", "<wbr>");
const oldHTML = nodeElement.outerHTML;
nextSibling.previousElementSibling.remove();
const newlineNode = document.createTextNode("\n");
startElement.after(document.createTextNode(Constants.ZWSP));
startElement.after(newlineNode);
range.selectNode(newlineNode);
range.collapse(false);
updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, oldHTML);
return true;
}
}
}
// 行内元素末尾软换行 https://github.com/siyuan-note/insider/issues/886
if (startElement.nodeType === 3) {
startElement = startElement.parentElement;

View file

@ -949,16 +949,10 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
if (event.altKey) {
addSubList(protyle, nodeElement, range);
} else {
if (!event.shiftKey) {
enter(nodeElement, range, protyle);
event.stopPropagation();
event.preventDefault();
return;
} else if (nodeElement.getAttribute("data-type") === "NodeAttributeView") {
event.stopPropagation();
event.preventDefault();
return;
}
enter(nodeElement, range, protyle);
event.stopPropagation();
event.preventDefault();
return;
}
}