jam411 3 лет назад
Родитель
Сommit
9fe7c08728

+ 2 - 8
packages/app/src/components/PageEditor/CodeMirrorEditor.jsx

@@ -1064,12 +1064,6 @@ class CodeMirrorEditor extends AbstractEditor {
           ref={this.cm}
           ref={this.cm}
           className={additionalClasses}
           className={additionalClasses}
           placeholder="search"
           placeholder="search"
-          // == temporary deactivate editorDidMount to use https://github.com/scniro/react-codemirror2/issues/284#issuecomment-1155928554
-          // editorDidMount={(editor) => {
-          // // add event handlers
-          //   editor.on('paste', this.pasteHandler);
-          //   editor.on('scrollCursorIntoView', this.scrollCursorIntoViewHandler);
-          // }}
           value={this.props.value}
           value={this.props.value}
           options={{
           options={{
             indentUnit: this.props.indentSize,
             indentUnit: this.props.indentSize,
@@ -1116,8 +1110,8 @@ class CodeMirrorEditor extends AbstractEditor {
           }}
           }}
           onKeyPress={this.keyPressHandler}
           onKeyPress={this.keyPressHandler}
           onKeyDown={this.keyDownHandler}
           onKeyDown={this.keyDownHandler}
-          pasteHandler={this.pasteHandler}
-          scrollCursorIntoViewHandler={this.scrollCursorIntoViewHandler}
+          onPasteFiles={this.pasteHandler}
+          onScrollCursorIntoView={this.scrollCursorIntoViewHandler}
         />
         />
 
 
         { this.renderLoadingKeymapOverlay() }
         { this.renderLoadingKeymapOverlay() }

+ 8 - 11
packages/app/src/components/UncontrolledCodeMirror.tsx

@@ -22,19 +22,17 @@ export interface UncontrolledCodeMirrorProps extends ICodeMirror {
   value: string;
   value: string;
   isGfmMode?: boolean;
   isGfmMode?: boolean;
   lineNumbers?: boolean;
   lineNumbers?: boolean;
-  onScrollCursorIntoView?: (line: number) => void;
   onSave?: () => Promise<void>;
   onSave?: () => Promise<void>;
-  onPasteFiles?: (event: Event) => void;
   onCtrlEnter?: (event: Event) => void;
   onCtrlEnter?: (event: Event) => void;
-  pasteHandler?: (editor: any, event: Event) => void;
-  scrollCursorIntoViewHandler?: (editor: any, event: Event) => void;
+  onPasteFiles?: (editor: any, event: Event) => void;
+  onScrollCursorIntoView?: (editor: any, event: Event) => void;
 }
 }
 
 
 export const UncontrolledCodeMirror = React.forwardRef<CodeMirror|null, UncontrolledCodeMirrorProps>((props, forwardedRef): JSX.Element => {
 export const UncontrolledCodeMirror = React.forwardRef<CodeMirror|null, UncontrolledCodeMirrorProps>((props, forwardedRef): JSX.Element => {
 
 
   const {
   const {
     value, lineNumbers, options,
     value, lineNumbers, options,
-    pasteHandler, scrollCursorIntoViewHandler,
+    onPasteFiles, onScrollCursorIntoView,
     ...rest
     ...rest
   } = props;
   } = props;
 
 
@@ -44,14 +42,13 @@ export const UncontrolledCodeMirror = React.forwardRef<CodeMirror|null, Uncontro
 
 
   const editorDidMountHandler = useCallback((editor: Editor): void => {
   const editorDidMountHandler = useCallback((editor: Editor): void => {
     editorRef.current = editor;
     editorRef.current = editor;
-
-    if (pasteHandler != null) {
-      editor.on('paste', pasteHandler);
+    if (onPasteFiles != null) {
+      editor.on('paste', onPasteFiles);
     }
     }
-    if (scrollCursorIntoViewHandler != null) {
-      editor.on('scrollCursorIntoView', scrollCursorIntoViewHandler);
+    if (onScrollCursorIntoView != null) {
+      editor.on('scrollCursorIntoView', onScrollCursorIntoView);
     }
     }
-  }, [pasteHandler, scrollCursorIntoViewHandler]);
+  }, [onPasteFiles, onScrollCursorIntoView]);
 
 
   const editorWillUnmountHandler = useCallback((): void => {
   const editorWillUnmountHandler = useCallback((): void => {
     // workaround to fix editor duplicating by https://github.com/scniro/react-codemirror2/issues/284#issuecomment-1155928554
     // workaround to fix editor duplicating by https://github.com/scniro/react-codemirror2/issues/284#issuecomment-1155928554