|
@@ -3,6 +3,7 @@ import {
|
|
|
} from 'react';
|
|
} from 'react';
|
|
|
|
|
|
|
|
import { indentUnit } from '@codemirror/language';
|
|
import { indentUnit } from '@codemirror/language';
|
|
|
|
|
+import { EditorView } from '@codemirror/view';
|
|
|
import type { ReactCodeMirrorProps } from '@uiw/react-codemirror';
|
|
import type { ReactCodeMirrorProps } from '@uiw/react-codemirror';
|
|
|
|
|
|
|
|
import { GlobalCodeMirrorEditorKey } from '../../consts';
|
|
import { GlobalCodeMirrorEditorKey } from '../../consts';
|
|
@@ -54,6 +55,49 @@ export const CodeMirrorEditor = (props: Props): JSX.Element => {
|
|
|
|
|
|
|
|
}, [codeMirrorEditor, indentSize]);
|
|
}, [codeMirrorEditor, indentSize]);
|
|
|
|
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
|
+ const handlePaste = (event: ClipboardEvent) => {
|
|
|
|
|
+ event.preventDefault();
|
|
|
|
|
+
|
|
|
|
|
+ if (event.clipboardData == null) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (onUpload != null && event.clipboardData.types.includes('Files')) {
|
|
|
|
|
+ onUpload(Array.from(event.clipboardData.files));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (event.clipboardData.types.includes('text/plain')) {
|
|
|
|
|
+ const textData = event.clipboardData.getData('text/plain');
|
|
|
|
|
+ codeMirrorEditor?.replaceText(textData);
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ const extension = EditorView.domEventHandlers({
|
|
|
|
|
+ paste: handlePaste,
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ const cleanupFunction = codeMirrorEditor?.appendExtensions(extension);
|
|
|
|
|
+ return cleanupFunction;
|
|
|
|
|
+
|
|
|
|
|
+ }, [codeMirrorEditor, onUpload]);
|
|
|
|
|
+
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
|
+
|
|
|
|
|
+ const handleDrop = (event: DragEvent) => {
|
|
|
|
|
+ // prevents conflicts between codemirror and react-dropzone during file drops.
|
|
|
|
|
+ event.preventDefault();
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ const extension = EditorView.domEventHandlers({
|
|
|
|
|
+ drop: handleDrop,
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ const cleanupFunction = codeMirrorEditor?.appendExtensions(extension);
|
|
|
|
|
+ return cleanupFunction;
|
|
|
|
|
+
|
|
|
|
|
+ }, [codeMirrorEditor]);
|
|
|
|
|
+
|
|
|
const { getRootProps, open } = useFileDropzone({ onUpload });
|
|
const { getRootProps, open } = useFileDropzone({ onUpload });
|
|
|
|
|
|
|
|
return (
|
|
return (
|