Steven Fukase 4 years ago
parent
commit
d55c2ae1ab
1 changed files with 28 additions and 25 deletions
  1. 28 25
      packages/app/src/components/PageEditor/CodeMirrorEditor.jsx

+ 28 - 25
packages/app/src/components/PageEditor/CodeMirrorEditor.jsx

@@ -148,6 +148,8 @@ export default class CodeMirrorEditor extends AbstractEditor {
     this.showLinkEditHandler = this.showLinkEditHandler.bind(this);
     this.showHandsonTableHandler = this.showHandsonTableHandler.bind(this);
     this.showDrawioHandler = this.showDrawioHandler.bind(this);
+
+    this.initTextlintSettings = this.initTextlintSettings.bind(this);
   }
 
   init() {
@@ -155,6 +157,24 @@ export default class CodeMirrorEditor extends AbstractEditor {
     this.cmNoCdnScriptRoot = '/js/cdn';
     this.cmNoCdnStyleRoot = '/styles/cdn';
 
+    // TODO: Get configs from db
+    this.isLintEnabled = true;
+
+    this.textlintConfig = [
+      {
+        name: 'max-comma',
+      },
+      {
+        name: 'common-misspellings',
+        options: {
+          ignore: [
+            'isnt',
+            'yuo',
+          ],
+        },
+      },
+    ];
+
     this.interceptorManager = new InterceptorManager();
     this.interceptorManager.addInterceptors([
       new PreventMarkdownListInterceptor(),
@@ -170,6 +190,8 @@ export default class CodeMirrorEditor extends AbstractEditor {
       this.emojiAutoCompleteHelper = new EmojiAutoCompleteHelper(this.props.emojiStrategy);
       this.setState({ isEnabledEmojiAutoComplete: true });
     }
+
+    this.initTextlintSettings();
   }
 
   componentDidMount() {
@@ -195,6 +217,12 @@ export default class CodeMirrorEditor extends AbstractEditor {
     this.setKeymapMode(keymapMode);
   }
 
+  initTextlintSettings() {
+    console.log('init!');
+    this.textlintValidator = createValidator(this.textlintConfig);
+    this.codemirrorLintConfig = this.isLintEnabled ? { getAnnotations: this.textlintValidator, async: true } : undefined;
+  }
+
   getCodeMirror() {
     return this.cm.editor;
   }
@@ -857,31 +885,6 @@ export default class CodeMirrorEditor extends AbstractEditor {
     ];
   }
 
-  // TODO: Get configs from db
-  isLintEnabled = true;
-
-  textlintConfig = [
-    {
-      name: 'max-comma',
-    },
-    {
-      name: 'dummy-rule',
-    },
-    {
-      name: 'common-misspellings',
-      options: {
-        ignore: [
-          'isnt',
-          'yuo',
-        ],
-      },
-    },
-  ];
-
-  textlintValidator = createValidator(this.textlintConfig);
-
-  codemirrorLintConfig = this.isLintEnabled ? { getAnnotations: this.textlintValidator, async: true } : undefined;
-
   render() {
     const mode = this.state.isGfmMode ? 'gfm-growi' : undefined;
     const lint = this.codemirrorLintConfig;