Liyuan Li 5 tahun lalu
induk
melakukan
9d5bf8bb1a
5 mengubah file dengan 12 tambahan dan 1 penghapusan
  1. 4 1
      CHANGELOG.md
  2. 3 0
      demo/comment.js
  3. 3 0
      src/ts/util/editorCommonEvent.ts
  4. 1 0
      src/ts/wysiwyg/input.ts
  5. 1 0
      types/index.d.ts

+ 4 - 1
CHANGELOG.md

@@ -83,6 +83,7 @@
 
 ### v3.6.2 / 2020-11-xx
 
+* [810](https://github.com/Vanessa219/vditor/issues/810) 所见即所得模式划词评论功能改进 `修复缺陷`
 
 ### v3.6.1 / 2020-11-10
 
@@ -106,8 +107,10 @@
      ```
      comment?: {
          enable: boolean
-         add?(id: string, text: string): void
+         add?(id: string, text: string, commentsData: ICommentsData[]): void
          remove?(ids: string[]): void;
+         scroll?(top: number): void;
+         adjustTop?(commentsData: ICommentsData[]): void;
      };
      ```
 

+ 3 - 0
demo/comment.js

@@ -116,6 +116,9 @@ window.vditor = new Vditor('vditor', {
   placeholder: 'Hello, Vditor!',
   comment: {
     enable: true,
+    adjustTop(commentsData) {
+      matchCommentsTop(commentsData)
+    },
     add (id, text, commentsData) {
       commentsData.find((item, index) => {
         if (item.id === id) {

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

@@ -75,6 +75,9 @@ export const cutEvent =
     };
 
 export const scrollCenter = (vditor: IVditor) => {
+    if (vditor.currentMode === "wysiwyg" && vditor.options.comment.enable) {
+        vditor.options.comment.adjustTop(vditor.wysiwyg.getComments(vditor, true))
+    }
     if (!vditor.options.typewriterMode) {
         return;
     }

+ 1 - 0
src/ts/wysiwyg/input.ts

@@ -194,6 +194,7 @@ export const input = (vditor: IVditor, range: Range, event?: InputEvent) => {
 
         if (event && (event.inputType === "deleteContentBackward" || event.inputType === "deleteContentForward")) {
             vditor.wysiwyg.triggerRemoveComment(vditor);
+            vditor.options.comment.adjustTop(vditor.wysiwyg.getComments(vditor, true));
         }
     }
 

+ 1 - 0
types/index.d.ts

@@ -514,6 +514,7 @@ interface IOptions {
         add?(id: string, text: string, commentsData: ICommentsData[]): void
         remove?(ids: string[]): void;
         scroll?(top: number): void;
+        adjustTop?(commentsData: ICommentsData[]): void;
     };
     /** 主题。默认值: 'classic' */
     theme?: "classic" | "dark";