Vanessa 2024-10-12 13:11:07 +08:00
parent 3562cc0bb1
commit 50b97c0844

View File

@ -7,7 +7,7 @@ import {
hasPreviousSibling, hasPreviousSibling,
isNotEditBlock isNotEditBlock
} from "./getBlock"; } from "./getBlock";
import {transaction, updateTransaction} from "./transaction"; import {transaction, turnsIntoOneTransaction, updateTransaction} from "./transaction";
import {breakList, genListItemElement, listOutdent, updateListOrder} from "./list"; import {breakList, genListItemElement, listOutdent, updateListOrder} from "./list";
import {highlightRender} from "../render/highlightRender"; import {highlightRender} from "../render/highlightRender";
import {Constants} from "../../constants"; import {Constants} from "../../constants";
@ -249,6 +249,7 @@ export const enter = (blockElement: HTMLElement, range: Range, protyle: IProtyle
const undoOperation: IOperation[] = []; const undoOperation: IOperation[] = [];
let currentElement = blockElement; let currentElement = blockElement;
// 回车之前的块为 1\n\n2 时会产生多个块 // 回车之前的块为 1\n\n2 时会产生多个块
const selectsElement: Element[] = []
Array.from(enterElement.children).forEach((item: HTMLElement) => { Array.from(enterElement.children).forEach((item: HTMLElement) => {
if (item.dataset.nodeId === id) { if (item.dataset.nodeId === id) {
blockElement.before(item); blockElement.before(item);
@ -278,6 +279,7 @@ export const enter = (blockElement: HTMLElement, range: Range, protyle: IProtyle
} }
mathRender(item); mathRender(item);
currentElement = item; currentElement = item;
selectsElement.push(item);
}); });
Array.from(newElement.children).forEach((item: HTMLElement) => { Array.from(newElement.children).forEach((item: HTMLElement) => {
@ -299,8 +301,18 @@ export const enter = (blockElement: HTMLElement, range: Range, protyle: IProtyle
mathRender(currentElement.nextElementSibling); mathRender(currentElement.nextElementSibling);
} }
currentElement = item; currentElement = item;
selectsElement.push(item);
}); });
const parentElement = currentElement.parentElement
transaction(protyle, doOperation, undoOperation); transaction(protyle, doOperation, undoOperation);
if (parentElement.classList.contains("sb") && parentElement.getAttribute("data-sb-layout") === "col") {
turnsIntoOneTransaction({
protyle,
selectsElement,
type: "BlocksMergeSuperBlock",
level: "row"
});
}
focusBlock(currentElement); focusBlock(currentElement);
scrollCenter(protyle); scrollCenter(protyle);
return true; return true;