Liyuan Li 5 rokov pred
rodič
commit
48ebe9fbed

+ 3 - 0
demo/index.js

@@ -65,6 +65,9 @@ window.vditor = new Vditor('vditor', {
       mark: true,
     },
   },
+  comment: {
+    enable: true,
+  },
   toolbarConfig: {
     pin: true,
   },

+ 6 - 0
src/ts/util/Options.ts

@@ -12,6 +12,9 @@ export class Options {
         classes: {
             preview: "",
         },
+        comment: {
+            enable: false,
+        },
         counter: {
             enable: false,
             type: "markdown",
@@ -133,6 +136,9 @@ export class Options {
             if (this.options.hint?.emoji) {
                 this.defaultOptions.hint.emoji = this.options.hint.emoji;
             }
+            if (this.options.comment) {
+                this.defaultOptions.comment = this.options.comment;
+            }
         }
 
         const mergedOptions = merge(this.defaultOptions, this.options);

+ 3 - 1
src/ts/util/editorCommonEvent.ts

@@ -31,6 +31,8 @@ export const blurEvent = (vditor: IVditor, editorElement: HTMLElement) => {
             if (expandElement) {
                 expandElement.classList.remove("vditor-ir__node--expand");
             }
+        } else if (vditor.currentMode === "wysiwyg") {
+            vditor.wysiwyg.hideComment();
         }
         if (vditor.options.blur) {
             vditor.options.blur(getMarkdown(vditor));
@@ -199,7 +201,7 @@ export const selectEvent = (vditor: IVditor, editorElement: HTMLElement) => {
         editorElement.onmouseup = () => {
             const selectText = getSelectText(vditor[vditor.currentMode].element);
             if (selectText) {
-                if (vditor.currentMode === "wysiwyg") {
+                if (vditor.currentMode === "wysiwyg" && vditor.options.comment.enable) {
                     vditor.wysiwyg.showComment();
                 }
                 if (vditor.options.select) {

+ 3 - 2
types/index.d.ts

@@ -506,8 +506,9 @@ interface IOptions {
     };
     /** 评论 */
     comment?: {
-        add(id: string): void
-        remove(ids: string[]): void;
+        enable: boolean
+        add?(id: string): void
+        remove?(ids: string[]): void;
     };
     /** 主题。默认值: 'classic' */
     theme?: "classic" | "dark";