Sfoglia il codice sorgente

add optional to view

soumaeda 2 anni fa
parent
commit
f1a6f7ad3f

+ 2 - 2
packages/editor/src/components/CodeMirrorEditor/Toolbar/TextFormatTools.tsx

@@ -47,7 +47,7 @@ export const TextFormatTools = (props: TextFormatToolsType): JSX.Element => {
         view?.state.selection.main.from,
         view?.state.selection.main.from,
         view?.state.selection.main.to,
         view?.state.selection.main.to,
       );
       );
-      const cursorPos = view.state.selection.main.head;
+      const cursorPos = view?.state.selection.main.head;
       let curPosAfterReplacing = {};
       let curPosAfterReplacing = {};
       const insertText = view?.state.replaceSelection(prefix + selection + suffix);
       const insertText = view?.state.replaceSelection(prefix + selection + suffix);
 
 
@@ -57,7 +57,7 @@ export const TextFormatTools = (props: TextFormatToolsType): JSX.Element => {
           curPosAfterReplacing = cursorPos + prefix.length;
           curPosAfterReplacing = cursorPos + prefix.length;
         }
         }
         view?.dispatch({ selection: { anchor: curPosAfterReplacing } });
         view?.dispatch({ selection: { anchor: curPosAfterReplacing } });
-        view.focus();
+        view?.focus();
       }
       }
     };
     };
   }, [view]);
   }, [view]);