Browse Source

:art: fix https://github.com/Vanessa219/vditor/pull/1342

Vanessa 2 năm trước cách đây
mục cha
commit
9dbbc79203
4 tập tin đã thay đổi với 6 bổ sung6 xóa
  1. 2 0
      CHANGELOG.md
  2. 2 4
      src/ts/outline/index.ts
  3. 1 1
      src/ts/toolbar/EditMode.ts
  4. 1 1
      types/index.d.ts

+ 2 - 0
CHANGELOG.md

@@ -105,6 +105,8 @@
 
 ### v3.9.0 / 2023-01
 
+* [1342](https://github.com/Vanessa219/vditor/pull/1342) 初始化后不自动聚焦 `改进功能`
+* [1341](https://github.com/Vanessa219/vditor/pull/1341) 支持 markmap `引入特性`
 * [1335](https://github.com/Vanessa219/vditor/issues/1335) 嵌入 Iframe 时无法导出 PDF `修复缺陷`
 
 ### v3.8.18 / 2022-11-01

+ 2 - 4
src/ts/outline/index.ts

@@ -24,7 +24,7 @@ export class Outline {
         return html;
     }
 
-    public toggle(vditor: IVditor, show = true) {
+    public toggle(vditor: IVditor, show = true, focus = true) {
         const btnElement = vditor.toolbar.elements.outline?.firstElementChild;
         if (show && window.innerWidth >= Constants.MOBILE_WIDTH) {
             this.element.style.display = "block";
@@ -34,12 +34,10 @@ export class Outline {
             this.element.style.display = "none";
             btnElement?.classList.remove("vditor-menu--current");
         }
-        if (getSelection().rangeCount > 0) {
+        if (focus && getSelection().rangeCount > 0) {
             const range = getSelection().getRangeAt(0);
             if (vditor[vditor.currentMode].element.contains(range.startContainer)) {
                 setSelectionFocus(range);
-            } else if (vditor[vditor.currentMode].element.contains(getSelection().focusNode)) {
-                vditor[vditor.currentMode].element.focus();
             }
         }
         setPadding(vditor);

+ 1 - 1
src/ts/toolbar/EditMode.ts

@@ -145,7 +145,7 @@ export const setEditMode = (vditor: IVditor, type: string, event: Event | string
         vditor.toolbar.elements["edit-mode"].querySelector(`button[data-mode="${vditor.currentMode}"]`).classList.add("vditor-menu--current");
     }
 
-    vditor.outline.toggle(vditor, vditor.currentMode !== "sv" && vditor.options.outline.enable);
+    vditor.outline.toggle(vditor, vditor.currentMode !== "sv" && vditor.options.outline.enable, typeof event !== "string");
 };
 
 export class EditMode extends MenuItem {

+ 1 - 1
types/index.d.ts

@@ -693,7 +693,7 @@ interface IVditor {
     outline: {
         element: HTMLElement,
         render(vditor: IVditor): string,
-        toggle(vditor: IVditor, show?: boolean): void,
+        toggle(vditor: IVditor, show?: boolean, focus?: boolean): void,
     };
     toolbar?: {
         elements?: { [key: string]: HTMLElement },