فهرست منبع

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

Vanessa 8 ماه پیش
والد
کامیت
84d7848583
2فایلهای تغییر یافته به همراه10 افزوده شده و 2 حذف شده
  1. 8 0
      app/src/protyle/util/selection.ts
  2. 2 2
      app/src/protyle/wysiwyg/keydown.ts

+ 8 - 0
app/src/protyle/util/selection.ts

@@ -136,6 +136,14 @@ export const getEditorRange = (element: Element) => {
     if (getSelection().rangeCount > 0) {
         range = getSelection().getRangeAt(0);
         if (element.isSameNode(range.startContainer) || element.contains(range.startContainer)) {
+            // 有时候点击编辑器头部需要矫正到第一个块中
+            if (range.toString() === "" && range.startContainer.nodeType === 1 && range.startOffset === 0 &&
+                (range.startContainer as HTMLElement).classList.contains("protyle-wysiwyg")) {
+                const focusRange = focusBlock(range.startContainer.firstChild as Element);
+                if (focusRange) {
+                    return focusRange;
+                }
+            }
             return range;
         }
     }

+ 2 - 2
app/src/protyle/wysiwyg/keydown.ts

@@ -1180,8 +1180,8 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
                 // https://github.com/siyuan-note/siyuan/issues/12989
                 const cardElement = hasClosestByClassName(range.startContainer, "card__main", true);
                 if (cardElement && document.activeElement && document.activeElement.classList.contains("protyle-wysiwyg")) {
-                    (cardElement.querySelector(".card__action button") as HTMLElement).focus()
-                     hideElements(["select"], protyle);
+                    (cardElement.querySelector(".card__action:not(.fn__none) button") as HTMLElement).focus()
+                    hideElements(["select"], protyle);
                 }
             } else {
                 if (!protyle.toolbar.element.classList.contains("fn__none") ||