Vanessa 2026-01-15 22:36:00 +08:00
parent 94ae418708
commit d9535ea541
2 changed files with 21 additions and 5 deletions

View file

@ -582,6 +582,7 @@ export const focusByWbr = (element: Element, range: Range) => {
range.collapse(true);
wbrElement.remove();
focusByRange(range);
return range;
};
export const focusByRange = (range: Range) => {

View file

@ -271,14 +271,22 @@ export const removeBlock = async (protyle: IProtyle, blockElement: Element, rang
return;
}
const isCallout = blockElement.parentElement.classList.contains("callout-content");
if (!blockElement.previousElementSibling &&
(blockType !== "NodeHeading" || (blockType === "NodeHeading" && type === "Delete")) &&
(blockElement.parentElement.getAttribute("data-type") === "NodeBlockquote" || isCallout)) {
let isCallout = blockElement.parentElement.classList.contains("callout-content");
if (type === "Delete") {
const bqCaElement = hasClosestByClassName(blockElement, "bq") || hasClosestByClassName(blockElement, "callout");
if (bqCaElement) {
isCallout = bqCaElement.classList.contains("callout");
blockElement = isCallout ? bqCaElement.querySelector(".callout-content").firstElementChild : bqCaElement.firstElementChild;
}
}
const blockParentElement = isCallout ? blockElement.parentElement.parentElement : blockElement.parentElement;
if (!blockElement.previousElementSibling && (blockElement.parentElement.getAttribute("data-type") === "NodeBlockquote" || isCallout) && (
(type !== "Delete" && blockType !== "NodeHeading") ||
(type === "Delete" && blockParentElement.parentElement.classList.contains("protyle-wysiwyg"))
)) {
if (type !== "Delete") {
range.insertNode(document.createElement("wbr"));
}
const blockParentElement = isCallout ? blockElement.parentElement.parentElement : blockElement.parentElement;
blockParentElement.insertAdjacentElement("beforebegin", blockElement);
if (isCallout ? blockParentElement.querySelector(".callout-content").childElementCount === 0 :
blockParentElement.childElementCount === 1) {
@ -327,6 +335,13 @@ export const removeBlock = async (protyle: IProtyle, blockElement: Element, rang
removeLi(protyle, blockElement, range, type === "Delete");
return;
}
if (type === "Delete") {
const liElement = hasClosestByClassName(blockElement, "li");
if (liElement) {
removeLi(protyle, liElement.firstElementChild.nextElementSibling, range, true);
return;
}
}
const previousElement = getPreviousBlock(blockElement) as HTMLElement;
// 设置 bq 和代码块光标
// 需放在列表处理后 https://github.com/siyuan-note/siyuan/issues/11606