Skip to content

Commit

Permalink
🎨 #12809
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Oct 18, 2024
1 parent e674cfe commit 8a42e07
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions app/src/protyle/util/editorCommonEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import {Constants} from "../../constants";
import {paste} from "./paste";
import {cancelSB, genEmptyElement, genSBElement, insertEmptyBlock} from "../../block/util";
import {transaction} from "../wysiwyg/transaction";
import {transaction, turnsIntoOneTransaction} from "../wysiwyg/transaction";
import {getTopAloneElement} from "../wysiwyg/getBlock";
import {updateListOrder} from "../wysiwyg/list";
import {fetchPost, fetchSyncPost} from "../../util/fetch";
Expand Down Expand Up @@ -271,6 +271,7 @@ const dragSb = async (protyle: IProtyle, sourceElements: Element[], targetElemen
previousID: sbElement.previousElementSibling?.getAttribute("data-node-id"),
parentID: sbElement.parentElement.getAttribute("data-node-id") || protyle.block.parentID || protyle.block.rootID
}];
let hasFoldHeading = false;
if (newSourceElement) {
const newSourceId = newSourceElement.getAttribute("data-node-id");
sbElement.insertAdjacentElement("afterbegin", targetElement);
Expand Down Expand Up @@ -369,9 +370,12 @@ const dragSb = async (protyle: IProtyle, sourceElements: Element[], targetElemen
if (index === 0) {
afterPreviousID = isCopy ? copyId : id;
}
if (isCopy && item.getAttribute("data-type") === "NodeHeading" && item.getAttribute("fold") === "1") {
item.removeAttribute("fold");
foldHeadingIds.push({id, parentID});
if (item.getAttribute("data-type") === "NodeHeading" && item.getAttribute("fold") === "1") {
if (isCopy) {
item.removeAttribute("fold");
foldHeadingIds.push({id, parentID});
}
hasFoldHeading = true;
}
if (isCopy) {
undoOperations.push({
Expand Down Expand Up @@ -569,6 +573,14 @@ const dragSb = async (protyle: IProtyle, sourceElements: Element[], targetElemen
// 跨文档不支持撤销
transaction(protyle, doOperations);
}
if (direct === "col" && (sourceElements.length > 1 || hasFoldHeading) && !isCopy) {
turnsIntoOneTransaction({
protyle,
selectsElement: sourceElements.reverse(),
type: "BlocksMergeSuperBlock",
level: "row"
});
}
focusBlock(sourceElements[0]);
};

Expand Down Expand Up @@ -753,6 +765,23 @@ const dragSame = async (protyle: IProtyle, sourceElements: Element[], targetElem
// 跨文档不支持撤销
transaction(protyle, doOperations);
}
let hasFoldHeading = false;
sourceElements.find(item => {
if (item.getAttribute("data-type") === "NodeHeading" && item.getAttribute("fold") === "1") {
hasFoldHeading = true;
return true;
}
})
if (!isCopy && (sourceElements.length > 1 || hasFoldHeading) &&
sourceElements[0].parentElement.classList.contains("sb") &&
sourceElements[0].parentElement.getAttribute("data-sb-layout") === "col") {
turnsIntoOneTransaction({
protyle,
selectsElement: sourceElements.reverse(),
type: "BlocksMergeSuperBlock",
level: "row"
});
}
focusBlock(sourceElements[0]);
};

Expand Down

0 comments on commit 8a42e07

Please sign in to comment.