Vanessa 2024-11-15 13:30:41 +08:00
parent ab147598e1
commit 84d7848583
2 changed files with 10 additions and 2 deletions

View file

@ -136,6 +136,14 @@ export const getEditorRange = (element: Element) => {
if (getSelection().rangeCount > 0) {
range = getSelection().getRangeAt(0);
if (element.isSameNode(range.startContainer) || element.contains(range.startContainer)) {
// 有时候点击编辑器头部需要矫正到第一个块中
if (range.toString() === "" && range.startContainer.nodeType === 1 && range.startOffset === 0 &&
(range.startContainer as HTMLElement).classList.contains("protyle-wysiwyg")) {
const focusRange = focusBlock(range.startContainer.firstChild as Element);
if (focusRange) {
return focusRange;
}
}
return range;
}
}

View file

@ -1180,8 +1180,8 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
// https://github.com/siyuan-note/siyuan/issues/12989
const cardElement = hasClosestByClassName(range.startContainer, "card__main", true);
if (cardElement && document.activeElement && document.activeElement.classList.contains("protyle-wysiwyg")) {
(cardElement.querySelector(".card__action button") as HTMLElement).focus()
hideElements(["select"], protyle);
(cardElement.querySelector(".card__action:not(.fn__none) button") as HTMLElement).focus()
hideElements(["select"], protyle);
}
} else {
if (!protyle.toolbar.element.classList.contains("fn__none") ||