Vanessa 2025-12-28 16:54:30 +08:00
parent 43bf12743c
commit 30ff7c0d13
6 changed files with 33 additions and 17 deletions

View file

@ -191,7 +191,8 @@ export const insertEmptyBlock = (protyle: IProtyle, position: InsertPosition, id
protyle,
selectsElement: position === "afterend" ? [blockElement, blockElement.nextElementSibling] : [blockElement.previousElementSibling, blockElement],
type: "BlocksMergeSuperBlock",
level: "row"
level: "row",
unfocus: true,
});
}
focusByWbr(protyle.wysiwyg.element, range);

View file

@ -426,7 +426,8 @@ const dragSb = async (protyle: IProtyle, sourceElements: Element[], targetElemen
protyle,
selectsElement: newSourceParentElement.reverse(),
type: "BlocksMergeSuperBlock",
level: "row"
level: "row",
unfocus: true,
});
}
if (document.contains(sourceElements[0])) {
@ -515,7 +516,8 @@ const dragSame = async (protyle: IProtyle, sourceElements: Element[], targetElem
protyle,
selectsElement: newSourceParentElement.reverse(),
type: "BlocksMergeSuperBlock",
level: "row"
level: "row",
unfocus: true,
});
}
if (document.contains(sourceElements[0])) {

View file

@ -1,7 +1,7 @@
import {genEmptyElement, genHeadingElement, insertEmptyBlock} from "../../block/util";
import {focusByRange, focusByWbr, getSelectionOffset, setLastNodeRange} from "../util/selection";
import {
getContenteditableElement,
getContenteditableElement, getParentBlock,
getTopEmptyElement,
hasNextSibling,
hasPreviousSibling,
@ -117,12 +117,10 @@ export const enter = (blockElement: HTMLElement, range: Range, protyle: IProtyle
}
// bq || callout
const isCallout = blockElement.parentElement.classList.contains("callout-content");
const parentBlockElement = isCallout ? blockElement.parentElement.parentElement : blockElement.parentElement;
if (editableElement.textContent.replace(Constants.ZWSP, "").replace("\n", "") === "" &&
((blockElement.nextElementSibling && blockElement.nextElementSibling.classList.contains("protyle-attr") &&
blockElement.parentElement.getAttribute("data-type") === "NodeBlockquote") ||
(isCallout && !blockElement.nextElementSibling))) {
(blockElement.parentElement.classList.contains("callout-content") && !blockElement.nextElementSibling))) {
range.insertNode(document.createElement("wbr"));
const topElement = getTopEmptyElement(blockElement);
const blockId = blockElement.getAttribute("data-node-id");
@ -137,6 +135,7 @@ export const enter = (blockElement: HTMLElement, range: Range, protyle: IProtyle
id: topId,
data: topElement.outerHTML,
};
let parentBlockElement = getParentBlock(blockElement);
if (topId === blockId) {
doInsert.previousID = parentBlockElement.getAttribute("data-node-id");
undoInsert.previousID = blockElement.previousElementSibling.getAttribute("data-node-id");
@ -156,13 +155,15 @@ export const enter = (blockElement: HTMLElement, range: Range, protyle: IProtyle
action: "delete",
id: blockId,
}, undoInsert]);
parentBlockElement = getParentBlock(blockElement);
if (topId === blockId && parentBlockElement.classList.contains("sb") &&
parentBlockElement.getAttribute("data-sb-layout") === "col") {
turnsIntoOneTransaction({
protyle,
selectsElement: [blockElement.previousElementSibling, blockElement],
type: "BlocksMergeSuperBlock",
level: "row"
level: "row",
unfocus: true,
});
}
focusByWbr(blockElement, range);
@ -197,7 +198,7 @@ export const enter = (blockElement: HTMLElement, range: Range, protyle: IProtyle
data: newElement.outerHTML,
id: newId,
previousID: blockElement.previousElementSibling ? blockElement.previousElementSibling.getAttribute("data-node-id") : "",
parentID: parentBlockElement.getAttribute("data-node-id") || protyle.block.parentID
parentID: getParentBlock(blockElement).getAttribute("data-node-id") || protyle.block.parentID
}], [{
action: "delete",
id: newId,
@ -209,7 +210,7 @@ export const enter = (blockElement: HTMLElement, range: Range, protyle: IProtyle
}
range.insertNode(document.createElement("wbr"));
const html = blockElement.outerHTML;
const parentHTML = parentBlockElement.outerHTML;
const parentHTML = getParentBlock(blockElement).outerHTML;
if (range.toString() !== "") {
// 选中数学公式后回车取消选中 https://github.com/siyuan-note/siyuan/issues/12637#issuecomment-2381106949
const mathElement = hasClosestByAttribute(range.startContainer, "data-type", "inline-math");
@ -353,7 +354,8 @@ export const enter = (blockElement: HTMLElement, range: Range, protyle: IProtyle
protyle,
selectsElement,
type: "BlocksMergeSuperBlock",
level: "row"
level: "row",
unfocus: true,
});
}
focusByWbr(currentElement, range);

View file

@ -513,7 +513,8 @@ export const listOutdent = (protyle: IProtyle, liItemElements: Element[], range:
protyle,
selectsElement: [liElement, liElement.nextElementSibling],
type: "BlocksMergeSuperBlock",
level: "row"
level: "row",
unfocus: true,
});
}
focusByWbr(parentLiItemElement, range);

View file

@ -655,7 +655,8 @@ const removeLi = (protyle: IProtyle, blockElement: Element, range: Range, isDele
protyle,
selectsElement: selectsElement.reverse(),
type: "BlocksMergeSuperBlock",
level: "row"
level: "row",
unfocus: true,
});
}
focusByWbr(protyle.wysiwyg.element, range);

View file

@ -13,7 +13,7 @@ import {getAllModels} from "../../layout/getAll";
/// #endif
import {avRender, refreshAV} from "../render/av/render";
import {removeFoldHeading} from "../util/heading";
import {genEmptyElement, genSBElement} from "../../block/util";
import {cancelSB, genEmptyElement, genSBElement} from "../../block/util";
import {hideElements} from "../ui/hideElements";
import {reloadProtyle} from "../util/reload";
import {countBlockWord} from "../../layout/status";
@ -935,11 +935,12 @@ export const onTransaction = (protyle: IProtyle, operation: IOperation, isUndo:
}
};
export const turnsIntoOneTransaction = (options: {
export const turnsIntoOneTransaction = async (options: {
protyle: IProtyle,
selectsElement: Element[],
type: TTurnIntoOne,
level?: TTurnIntoOneSub
level?: TTurnIntoOneSub,
unfocus?: boolean
}) => {
let parentElement: Element;
const id = Lute.NewNodeID();
@ -1048,8 +1049,16 @@ export const turnsIntoOneTransaction = (options: {
blockRender(options.protyle, item);
}
});
if ((["Blocks2Blockquote", "Blocks2Callout"].includes(options.type) || options.type.endsWith("Ls")) &&
parentElement.parentElement.classList.contains("sb") && parentElement.parentElement.childElementCount === 2) {
const cancelOperations = await cancelSB(options.protyle, parentElement.parentElement);
doOperations.push(...cancelOperations.doOperations);
undoOperations.splice(0, 0, ...cancelOperations.undoOperations);
}
transaction(options.protyle, doOperations, undoOperations);
focusBlock(options.protyle.wysiwyg.element.querySelector(`[data-node-id="${options.selectsElement[0].getAttribute("data-node-id")}"]`));
if (!options.unfocus) {
focusBlock(options.protyle.wysiwyg.element.querySelector(`[data-node-id="${options.selectsElement[0].getAttribute("data-node-id")}"]`));
}
hideElements(["gutter"], options.protyle);
};