From f17e341dbc0562508df20b210105b4890dcb75af Mon Sep 17 00:00:00 2001 From: Vanessa Date: Fri, 15 Nov 2024 23:01:54 +0800 Subject: [PATCH] :bug: https://github.com/siyuan-note/siyuan/issues/13113 --- app/src/protyle/header/Title.ts | 3 ++- app/src/protyle/util/selection.ts | 15 +++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) 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 {