|
|
@@ -22,21 +22,33 @@ export interface UncontrolledCodeMirrorProps extends ICodeMirror {
|
|
|
value: string;
|
|
|
isGfmMode?: boolean;
|
|
|
lineNumbers?: boolean;
|
|
|
- onScrollCursorIntoView?: (line: number) => void;
|
|
|
onSave?: () => Promise<void>;
|
|
|
- onPasteFiles?: (event: Event) => void;
|
|
|
onCtrlEnter?: (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 => {
|
|
|
|
|
|
- const wrapperRef = useRef<CodeMirror|null>();
|
|
|
+ const {
|
|
|
+ value, lineNumbers, options,
|
|
|
+ onPasteFiles, onScrollCursorIntoView,
|
|
|
+ ...rest
|
|
|
+ } = props;
|
|
|
|
|
|
const editorRef = useRef<Editor>();
|
|
|
|
|
|
+ const wrapperRef = useRef<CodeMirror|null>();
|
|
|
+
|
|
|
const editorDidMountHandler = useCallback((editor: Editor): void => {
|
|
|
editorRef.current = editor;
|
|
|
- }, []);
|
|
|
+ if (onPasteFiles != null) {
|
|
|
+ editor.on('paste', onPasteFiles);
|
|
|
+ }
|
|
|
+ if (onScrollCursorIntoView != null) {
|
|
|
+ editor.on('scrollCursorIntoView', onScrollCursorIntoView);
|
|
|
+ }
|
|
|
+ }, [onPasteFiles, onScrollCursorIntoView]);
|
|
|
|
|
|
const editorWillUnmountHandler = useCallback((): void => {
|
|
|
// workaround to fix editor duplicating by https://github.com/scniro/react-codemirror2/issues/284#issuecomment-1155928554
|
|
|
@@ -48,11 +60,6 @@ export const UncontrolledCodeMirror = React.forwardRef<CodeMirror|null, Uncontro
|
|
|
}
|
|
|
}, []);
|
|
|
|
|
|
- const {
|
|
|
- value, lineNumbers, options,
|
|
|
- ...rest
|
|
|
- } = props;
|
|
|
-
|
|
|
// default true
|
|
|
const isGfmMode = rest.isGfmMode ?? true;
|
|
|
|