mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-14 16:11:00 +08:00
This commit is contained in:
parent
d8960fd253
commit
45820fec1c
@ -560,8 +560,23 @@ export const focusBlock = (element: Element, parentElement?: HTMLElement, toStar
|
|||||||
range = setFirstNodeRange(cursorElement, getEditorRange(cursorElement));
|
range = setFirstNodeRange(cursorElement, getEditorRange(cursorElement));
|
||||||
range.collapse(true);
|
range.collapse(true);
|
||||||
} else {
|
} else {
|
||||||
|
let focusHljs = false
|
||||||
// 定位到末尾 https://github.com/siyuan-note/siyuan/issues/5982
|
// 定位到末尾 https://github.com/siyuan-note/siyuan/issues/5982
|
||||||
|
if (cursorElement.classList.contains("hljs")) {
|
||||||
|
// 代码块末尾定位需在 /n 之前 https://github.com/siyuan-note/siyuan/issues/9141,https://github.com/siyuan-note/siyuan/issues/9189
|
||||||
|
let lastNode = cursorElement.lastChild
|
||||||
|
if (lastNode.textContent === "" && lastNode.nodeType === 3) {
|
||||||
|
lastNode = hasPreviousSibling(cursorElement.lastChild) as HTMLElement
|
||||||
|
}
|
||||||
|
if (lastNode && lastNode.textContent.endsWith("\n")) {
|
||||||
|
range = getEditorRange(cursorElement);
|
||||||
|
range.setStart(lastNode, lastNode.textContent.length - 1)
|
||||||
|
focusHljs = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!focusHljs) {
|
||||||
range = setLastNodeRange(cursorElement, getEditorRange(cursorElement));
|
range = setLastNodeRange(cursorElement, getEditorRange(cursorElement));
|
||||||
|
}
|
||||||
range.collapse(false);
|
range.collapse(false);
|
||||||
}
|
}
|
||||||
focusByRange(range);
|
focusByRange(range);
|
||||||
|
@ -385,7 +385,7 @@ export const removeBlock = (protyle: IProtyle, blockElement: Element, range: Ran
|
|||||||
|
|
||||||
const parentElement = blockElement.parentElement;
|
const parentElement = blockElement.parentElement;
|
||||||
const editableElement = getContenteditableElement(blockElement);
|
const editableElement = getContenteditableElement(blockElement);
|
||||||
let previousLastElement = getLastBlock(previousElement) as HTMLElement;
|
const previousLastElement = getLastBlock(previousElement) as HTMLElement;
|
||||||
const isSelectNode = previousLastElement && (previousLastElement.classList.contains("table") || previousLastElement.classList.contains("render-node") || previousLastElement.classList.contains("iframe") || previousLastElement.classList.contains("hr") || previousLastElement.classList.contains("code-block"));
|
const isSelectNode = previousLastElement && (previousLastElement.classList.contains("table") || previousLastElement.classList.contains("render-node") || previousLastElement.classList.contains("iframe") || previousLastElement.classList.contains("hr") || previousLastElement.classList.contains("code-block"));
|
||||||
const previousId = previousLastElement.getAttribute("data-node-id");
|
const previousId = previousLastElement.getAttribute("data-node-id");
|
||||||
if (isSelectNode) {
|
if (isSelectNode) {
|
||||||
@ -411,9 +411,7 @@ export const removeBlock = (protyle: IProtyle, blockElement: Element, range: Ran
|
|||||||
} else {
|
} else {
|
||||||
transaction(protyle, doOperations, undoOperations);
|
transaction(protyle, doOperations, undoOperations);
|
||||||
}
|
}
|
||||||
// toStart 参数不能为 false, 否则 https://github.com/siyuan-note/siyuan/issues/9141
|
focusBlock(protyle.wysiwyg.element.querySelector(`[data-node-id="${previousId}"]`), undefined, false);
|
||||||
previousLastElement = protyle.wysiwyg.element.querySelector(`[data-node-id="${previousId}"]`);
|
|
||||||
focusBlock(previousLastElement, undefined, getContenteditableElement(previousLastElement).textContent === "\n");
|
|
||||||
} else {
|
} else {
|
||||||
focusBlock(previousLastElement, undefined, false);
|
focusBlock(previousLastElement, undefined, false);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user