Skip to content

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

:bug: fix https://github.com/siyuan-note/siyuan/issues/6156

Vanessab5df5e2f9ada
diff --git a/app/src/protyle/util/selection.ts b/app/src/protyle/util/selection.ts
index 8a4745541a..034820a9c8 100644
--- a/app/src/protyle/util/selection.ts
+++ b/app/src/protyle/util/selection.ts
@@ -204,7 +204,8 @@ export const getSelectionPosition = (nodeElement: Element, range?: Range) => {
}
}
} else {
- cursorRect = range.getBoundingClientRect();
+ const rects = range.getClientRects(); // 由于长度过长折行,光标在行首时有多个 rects https://github.com/siyuan-note/siyuan/issues/6156
+ cursorRect = rects[rects.length - 1];
}
return {
diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts
index 63d358cd14..00ed710099 100644
--- a/app/src/protyle/wysiwyg/keydown.ts
+++ b/app/src/protyle/wysiwyg/keydown.ts
@@ -592,7 +592,8 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
nodeElement.contains(firstEditElement)
) ||
(!firstEditElement && nodeElement.isSameNode(protyle.wysiwyg.element.firstElementChild))) {
- if (nodeEditableElement?.textContent.substr(0, position.end).indexOf("\n") === -1) {
+ // 不能用\n判断,否则文字过长折行将错误 https://github.com/siyuan-note/siyuan/issues/6156
+ if (getSelectionPosition(nodeElement, range).top - protyle.wysiwyg.element.getBoundingClientRect().top < 40) {
if (protyle.title && (protyle.wysiwyg.element.firstElementChild.getAttribute("data-eof") === "true" ||
protyle.contentElement.scrollTop === 0)) {
protyle.title.editElement.focus();