diff --git a/app/src/protyle/wysiwyg/enter.ts b/app/src/protyle/wysiwyg/enter.ts index 1c7a2f7b1..8cba280b1 100644 --- a/app/src/protyle/wysiwyg/enter.ts +++ b/app/src/protyle/wysiwyg/enter.ts @@ -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", ""); - 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", ""); + 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; diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts index 773105232..3c4ac2a4a 100644 --- a/app/src/protyle/wysiwyg/keydown.ts +++ b/app/src/protyle/wysiwyg/keydown.ts @@ -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; } }