diff --git a/app/src/protyle/header/Title.ts b/app/src/protyle/header/Title.ts index d006f1d25..dc8d1c207 100644 --- a/app/src/protyle/header/Title.ts +++ b/app/src/protyle/header/Title.ts @@ -105,7 +105,8 @@ export class Title { if (event.key === "ArrowDown") { const rects = getSelection().getRangeAt(0).getClientRects(); // https://github.com/siyuan-note/siyuan/issues/11729 - if (this.editElement.getBoundingClientRect().bottom - rects[rects.length - 1].bottom < 25) { + if (rects.length === 0 // 标题为空时时 + || this.editElement.getBoundingClientRect().bottom - rects[rects.length - 1].bottom < 25) { const noContainerElement = getNoContainerElement(protyle.wysiwyg.element.firstElementChild); // https://github.com/siyuan-note/siyuan/issues/4923 if (noContainerElement) { diff --git a/app/src/protyle/util/selection.ts b/app/src/protyle/util/selection.ts index 956e9f9e4..a6487b91f 100644 --- a/app/src/protyle/util/selection.ts +++ b/app/src/protyle/util/selection.ts @@ -234,10 +234,17 @@ export const getSelectionPosition = (nodeElement: Element, range?: Range) => { } } else { const rects = range.getClientRects(); // 由于长度过长折行,光标在行首时有多个 rects https://github.com/siyuan-note/siyuan/issues/6156 - return { // 选中多行不应遮挡第一行 https://github.com/siyuan-note/siyuan/issues/7541 - left: rects[rects.length - 1].left, - top: rects[0].top - }; + if (range.toString()) { + return { // 选中多行不应遮挡第一行 https://github.com/siyuan-note/siyuan/issues/7541 + left: rects[rects.length - 1].left, + top: rects[0].top + }; + } else { + return { // 代码块首 https://github.com/siyuan-note/siyuan/issues/13113 + left: rects[rects.length - 1].left, + top: rects[rects.length - 1].top + }; + } } return {