Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: https://github.com/siyuan-note/siyuan/issues/17602

Vanessa94a1f67865e3
diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts
index 008645d3f9..e33a56c463 100644
--- a/app/src/protyle/wysiwyg/keydown.ts
+++ b/app/src/protyle/wysiwyg/keydown.ts
@@ -658,18 +658,9 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
) ||
(!firstEditElement && nodeElement === protyle.wysiwyg.element.firstElementChild)) {
// 不能用\n判断,否则文字过长折行将错误 https://github.com/siyuan-note/siyuan/issues/6156
- // 代码块中光标在第一行之后时不应跳到标题,因为 getSelectionPosition 对非第一行的计算是错误的 https://github.com/siyuan-note/siyuan/issues/17602
- let skipJumpToTitle = false;
- if (nodeElement.classList.contains("code-block")) {
- const hljsElement = nodeElement.querySelector(".hljs");
- const codeText = hljsElement?.textContent || "";
- const firstNewlineIndex = codeText.indexOf("\n");
- // 有多行并且在第一行之后,则需要skipJumpToTitle
- if (firstNewlineIndex !== -1 && position.start > firstNewlineIndex) {
- skipJumpToTitle = true;
- }
- }
- if ((getSelectionPosition(nodeEditableElement, range).top - nodeEditableElement.getBoundingClientRect().top < 20 || nodeElement.classList.contains("av")) && !skipJumpToTitle) {
+ // 空行 getSelectionPosition 计算有问题导致 https://github.com/siyuan-note/siyuan/issues/17602
+ const diff = getSelectionPosition(nodeEditableElement, range).top - nodeEditableElement.getBoundingClientRect().top;
+ if ((diff < 20 && diff !== 0) || nodeElement.classList.contains("av")) {
if (protyle.title && protyle.title.editElement &&
(protyle.wysiwyg.element.firstElementChild.getAttribute("data-eof") === "1" ||
protyle.contentElement.scrollTop === 0)) {