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/16179

Vanessa733f331a165e
diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts
index a159658e41..6712020051 100644
--- a/app/src/protyle/wysiwyg/index.ts
+++ b/app/src/protyle/wysiwyg/index.ts
@@ -3034,6 +3034,19 @@ export class WYSIWYG {
setTimeout(() => {
// 选中后,在选中的文字上点击需等待 range 更新
let newRange = getEditorRange(this.element);
+ // 点击两侧或间隙导致光标跳转到开头 https://github.com/siyuan-note/siyuan/issues/16179
+ if (hasClosestBlock(event.target) !== hasClosestBlock(newRange.startContainer) &&
+ this.element.firstElementChild.contains(newRange.startContainer)) {
+ const rect = this.element.getBoundingClientRect();
+ let rangeElement = document.elementFromPoint(rect.left + rect.width / 2, event.clientY);
+ if (rangeElement === this.element) {
+ rangeElement = document.elementFromPoint(rect.left + rect.width / 2, event.clientY + 8);
+ }
+ const blockElement = hasClosestBlock(rangeElement);
+ if (blockElement) {
+ newRange = focusBlock(blockElement, undefined, event.clientX < rect.left + parseInt(this.element.style.paddingLeft)) || newRange;
+ }
+ }
// https://github.com/siyuan-note/siyuan/issues/10357
const attrElement = hasClosestByClassName(newRange.endContainer, "protyle-attr");
if (attrElement) {