|
|
@@ -84,32 +84,36 @@ export const CodeMirrorEditor = (props: Props): JSX.Element => {
|
|
|
|
|
|
}, [codeMirrorEditor, indentSize]);
|
|
|
|
|
|
+ const pasteMode = editorSettings?.pasteMode;
|
|
|
useEffect(() => {
|
|
|
const handlePaste = (event: ClipboardEvent) => {
|
|
|
event.preventDefault();
|
|
|
|
|
|
const editor = codeMirrorEditor?.view;
|
|
|
|
|
|
- if (editor == null) {
|
|
|
+ if (editor == null || event.clipboardData == null) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if (event.clipboardData == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if (editorSettings?.pasteMode !== PasteMode.file && event.clipboardData.types.includes('text/plain')) {
|
|
|
+ if (event.clipboardData.types.includes('text/plain')) {
|
|
|
+ if (codeMirrorEditor == null) return;
|
|
|
|
|
|
- const textData = event.clipboardData.getData('text/plain');
|
|
|
+ if (pasteMode == null || pasteMode === PasteMode.both || pasteMode === PasteMode.text) {
|
|
|
+ const textData = event.clipboardData.getData('text/plain');
|
|
|
|
|
|
- const strFromBol = getStrFromBol(editor);
|
|
|
- const adjusted = adjustPasteData(strFromBol, textData);
|
|
|
+ const strFromBol = getStrFromBol(editor);
|
|
|
+ const adjusted = adjustPasteData(strFromBol, textData);
|
|
|
|
|
|
- codeMirrorEditor?.replaceText(adjusted);
|
|
|
+ codeMirrorEditor.replaceText(adjusted);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- if (editorSettings?.pasteMode !== PasteMode.text && onUpload != null && event.clipboardData.types.includes('Files')) {
|
|
|
- onUpload(Array.from(event.clipboardData.files));
|
|
|
+ if (event.clipboardData.types.includes('Files')) {
|
|
|
+ if (onUpload == null) return;
|
|
|
+
|
|
|
+ if (pasteMode == null || pasteMode === PasteMode.both || pasteMode === PasteMode.file) {
|
|
|
+ onUpload(Array.from(event.clipboardData.files));
|
|
|
+ }
|
|
|
}
|
|
|
};
|
|
|
|
|
|
@@ -120,7 +124,7 @@ export const CodeMirrorEditor = (props: Props): JSX.Element => {
|
|
|
const cleanupFunction = codeMirrorEditor?.appendExtensions(extension);
|
|
|
return cleanupFunction;
|
|
|
|
|
|
- }, [codeMirrorEditor, editorSettings?.pasteMode, onUpload]);
|
|
|
+ }, [codeMirrorEditor, pasteMode, onUpload]);
|
|
|
|
|
|
useEffect(() => {
|
|
|
|