This commit is contained in:
parent
d8960fd253
commit
45820fec1c
2 changed files with 18 additions and 5 deletions
|
@ -560,8 +560,23 @@ export const focusBlock = (element: Element, parentElement?: HTMLElement, toStar
|
|||
range = setFirstNodeRange(cursorElement, getEditorRange(cursorElement));
|
||||
range.collapse(true);
|
||||
} else {
|
||||
let focusHljs = false
|
||||
// 定位到末尾 https://github.com/siyuan-note/siyuan/issues/5982
|
||||
range = setLastNodeRange(cursorElement, getEditorRange(cursorElement));
|
||||
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.collapse(false);
|
||||
}
|
||||
focusByRange(range);
|
||||
|
|
|
@ -385,7 +385,7 @@ export const removeBlock = (protyle: IProtyle, blockElement: Element, range: Ran
|
|||
|
||||
const parentElement = blockElement.parentElement;
|
||||
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 previousId = previousLastElement.getAttribute("data-node-id");
|
||||
if (isSelectNode) {
|
||||
|
@ -411,9 +411,7 @@ export const removeBlock = (protyle: IProtyle, blockElement: Element, range: Ran
|
|||
} else {
|
||||
transaction(protyle, doOperations, undoOperations);
|
||||
}
|
||||
// toStart 参数不能为 false, 否则 https://github.com/siyuan-note/siyuan/issues/9141
|
||||
previousLastElement = protyle.wysiwyg.element.querySelector(`[data-node-id="${previousId}"]`);
|
||||
focusBlock(previousLastElement, undefined, getContenteditableElement(previousLastElement).textContent === "\n");
|
||||
focusBlock(protyle.wysiwyg.element.querySelector(`[data-node-id="${previousId}"]`), undefined, false);
|
||||
} else {
|
||||
focusBlock(previousLastElement, undefined, false);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue