Vanessa 2024-06-07 00:17:54 +08:00
parent f65b48f76e
commit bcb1bcc290
2 changed files with 16 additions and 8 deletions

View file

@ -486,10 +486,11 @@ export const focusByRange = (range: Range) => {
selection.addRange(range);
};
export const focusBlock = (element: Element, parentElement?: HTMLElement, toStart = true) => {
export const focusBlock = (element: Element, parentElement?: HTMLElement, toStart = true): false | Range => {
if (!element) {
return false;
}
// hr、嵌入块、数学公式、iframe、音频、视频、图表渲染块等删除段落块后光标位置矫正 https://github.com/siyuan-note/siyuan/issues/4143
if (element.classList.contains("render-node") || element.classList.contains("iframe") || element.classList.contains("hr") || element.classList.contains("av")) {
const range = document.createRange();
@ -609,6 +610,11 @@ export const focusBlock = (element: Element, parentElement?: HTMLElement, toStar
return range;
} else if (parentElement) {
parentElement.focus();
} else {
// li 下面为 hr、嵌入块、数学公式、iframe、音频、视频、图表渲染块等时递归处理
if (element.classList.contains("li")) {
return focusBlock(element.querySelector('[data-node-id]'), parentElement, toStart);
}
}
return false;
};

View file

@ -197,13 +197,7 @@ export const removeBlock = (protyle: IProtyle, blockElement: Element, range: Ran
removeBlock(protyle, blockElement, range, type);
return;
}
// 设置 bq 和代码块光标
if (["NodeCodeBlock", "NodeTable", "NodeAttributeView"].includes(blockType)) {
if (blockElement.previousElementSibling) {
focusBlock(blockElement.previousElementSibling, undefined, false);
}
return;
}
if (!blockElement.previousElementSibling && blockElement.parentElement.getAttribute("data-type") === "NodeBlockquote") {
range.insertNode(document.createElement("wbr"));
const blockParentElement = blockElement.parentElement;
@ -249,6 +243,14 @@ export const removeBlock = (protyle: IProtyle, blockElement: Element, range: Ran
removeLi(protyle, blockElement, range, type === "Delete");
return;
}
// 设置 bq 和代码块光标
// 需放在列表处理后 https://github.com/siyuan-note/siyuan/issues/11606
if (["NodeCodeBlock", "NodeTable", "NodeAttributeView"].includes(blockType)) {
if (blockElement.previousElementSibling) {
focusBlock(blockElement.previousElementSibling, undefined, false);
}
return;
}
if (blockType === "NodeHeading") {
turnsIntoTransaction({
protyle: protyle,