@@ -10,7 +10,7 @@ import {
1010
1111let uploadIdCounter = 0 ;
1212
13- function uploadFile ( dropzoneEl , file ) {
13+ function uploadFile ( dropzoneEl , file , placeholderCallback ) {
1414 return new Promise ( ( resolve ) => {
1515 const curUploadId = uploadIdCounter ++ ;
1616 file . _giteaUploadId = curUploadId ;
@@ -23,6 +23,8 @@ function uploadFile(dropzoneEl, file) {
2323 } ;
2424 dropzoneInst . on ( DropzoneCustomEventUploadDone , onUploadDone ) ;
2525 dropzoneInst . handleFiles ( [ file ] ) ;
26+ // if there is no setTimeout, then ComboMarkdownEditor.isUploading() does not working correctly
27+ setTimeout ( ( ) => placeholderCallback ( ) , 0 ) ;
2628 } ) ;
2729}
2830
@@ -99,17 +101,8 @@ async function handleUploadFiles(editor, dropzoneEl, files, e) {
99101 const { width, dppx} = await imageInfo ( file ) ;
100102 const placeholder = `[${ name } ](uploading ...)` ;
101103
102- // Placeholders should be inserted on uploading the thumnail.
103- // If not, the check upload process may fail
104- const handleInsertPlaceholder = ( ) => editor . insertPlaceholder ( placeholder ) ;
105- dropzoneEl . dropzone . on ( 'thumbnail' , handleInsertPlaceholder ) ;
106- try {
107- await uploadFile ( dropzoneEl , file ) ; // the "file" will get its "uuid" during the upload
108- } catch ( err ) {
109- throw err ;
110- } finally {
111- dropzoneEl . dropzone . off ( 'thumbnail' , handleInsertPlaceholder ) ;
112- }
104+ // the "file" will get its "uuid" during the upload
105+ await uploadFile ( dropzoneEl , file , ( ) => editor . insertPlaceholder ( placeholder ) ) ;
113106 editor . replacePlaceholder ( placeholder , generateMarkdownLinkForAttachment ( file , { width, dppx} ) ) ;
114107 }
115108}
0 commit comments