1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-09 08:45:55 +02:00

Desktop: Fixes #3324: Attaching an image, then cancelling the resize dialog, would crash the app

This commit is contained in:
Laurent Cozic 2020-06-04 09:08:13 +01:00
parent d9c266e3f1
commit 39a506ad52
3 changed files with 7 additions and 2 deletions

View File

@ -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);
}

View File

@ -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');

View File

@ -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;