mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-07 01:08:49 +01:00
This commit is contained in:
parent
a47e5929e7
commit
1f06440442
2 changed files with 23 additions and 21 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue