diff --git a/ElectronClient/gui/NoteEditor/NoteBody/AceEditor/AceEditor.tsx b/ElectronClient/gui/NoteEditor/NoteBody/AceEditor/AceEditor.tsx index 55dfa8240f..6518f5365d 100644 --- a/ElectronClient/gui/NoteEditor/NoteBody/AceEditor/AceEditor.tsx +++ b/ElectronClient/gui/NoteEditor/NoteBody/AceEditor/AceEditor.tsx @@ -101,6 +101,10 @@ function AceEditor(props: NoteBodyEditorProps, ref: any) { useListIdent({ editor }); const aceEditor_change = useCallback((newBody: string) => { + // Throw an error early to know what part of the code set the body to the + // wrong value. Otherwise it will trigger an error somewhere deep in React-Ace + // which will be hard to debug. + if (typeof newBody !== 'string') throw new Error('Body is not a string'); props_onChangeRef.current({ changeId: null, content: newBody }); }, []); @@ -258,7 +262,7 @@ function AceEditor(props: NoteBodyEditorProps, ref: any) { wrapSelectionWithStrings('', '', '', cmd.value.markdownTags.join('\n')); } else if (cmd.value.type === 'files') { const newBody = await commandAttachFileToBody(props.content, cmd.value.paths, { createFileURL: !!cmd.value.createFileURL }); - aceEditor_change(newBody); + if (newBody) aceEditor_change(newBody); } else { reg.logger().warn('AceEditor: unsupported drop item: ', cmd); } diff --git a/ElectronClient/gui/NoteEditor/NoteBody/TinyMCE/TinyMCE.tsx b/ElectronClient/gui/NoteEditor/NoteBody/TinyMCE/TinyMCE.tsx index 9bb0f88943..2c7a45bae0 100644 --- a/ElectronClient/gui/NoteEditor/NoteBody/TinyMCE/TinyMCE.tsx +++ b/ElectronClient/gui/NoteEditor/NoteBody/TinyMCE/TinyMCE.tsx @@ -182,6 +182,7 @@ const TinyMCE = (props:NoteBodyEditorProps, ref:any) => { const insertResourcesIntoContent = useCallback(async (filePaths:string[] = null, options:any = null) => { const resourceMd = await commandAttachFileToBody('', filePaths, options); + if (!resourceMd) return; const result = await props.markupToHtml(MarkupToHtml.MARKUP_LANGUAGE_MARKDOWN, resourceMd, markupRenderOptions({ bodyOnly: true })); editor.insertContent(result.html); // editor.fire('joplinChange'); diff --git a/ElectronClient/gui/NoteEditor/utils/resourceHandling.ts b/ElectronClient/gui/NoteEditor/utils/resourceHandling.ts index e7f2a1cfe2..2cc33f3b37 100644 --- a/ElectronClient/gui/NoteEditor/utils/resourceHandling.ts +++ b/ElectronClient/gui/NoteEditor/utils/resourceHandling.ts @@ -120,7 +120,7 @@ export async function handlePasteEvent(event:any) { const md = await commandAttachFileToBody('', [filePath]); await shim.fsDriver().remove(filePath); - output.push(md); + if (md) output.push(md); } } return output;