Просмотр исходного кода

prevent to come undefined to strFromBol

soumaeda 2 лет назад
Родитель
Сommit
b45d837040

+ 3 - 0
packages/editor/src/components/CodeMirrorEditor/CodeMirrorEditor.tsx

@@ -52,6 +52,9 @@ export const CodeMirrorEditor = (props: Props): JSX.Element => {
       if (event.key === 'Enter') {
         event.preventDefault();
         const editor = codeMirrorEditor?.view;
+        if (editor == null) {
+          return;
+        }
         newlineAndIndentContinueMarkdownList(editor);
       }
     };

+ 4 - 5
packages/editor/src/services/list-util/markdown-list-util.ts

@@ -48,12 +48,11 @@ const insertText = (editor: EditorView, text: string) => {
 export const newlineAndIndentContinueMarkdownList = (editor: EditorView): void => {
   const strFromBol = getStrFromBol(editor);
 
-  if (indentAndMarkRE.test(strFromBol)) {
+  const matchResult = strFromBol.match(indentAndMarkRE);
+
+  if (matchResult != null) {
     // continue list
-    const indentAndMark = strFromBol.match(indentAndMarkRE)[0];
+    const indentAndMark = matchResult[0];
     insertText(editor, indentAndMark);
   }
-  else {
-    insertText(editor, '\n');
-  }
 };