@@ -10,7 +10,7 @@ import {
10
10
11
11
let uploadIdCounter = 0 ;
12
12
13
- function uploadFile ( dropzoneEl , file ) {
13
+ function uploadFile ( dropzoneEl , file , placeholderCallback ) {
14
14
return new Promise ( ( resolve ) => {
15
15
const curUploadId = uploadIdCounter ++ ;
16
16
file . _giteaUploadId = curUploadId ;
@@ -23,6 +23,8 @@ function uploadFile(dropzoneEl, file) {
23
23
} ;
24
24
dropzoneInst . on ( DropzoneCustomEventUploadDone , onUploadDone ) ;
25
25
dropzoneInst . handleFiles ( [ file ] ) ;
26
+ // if there is no setTimeout, then ComboMarkdownEditor.isUploading() does not working correctly
27
+ setTimeout ( ( ) => placeholderCallback ( ) , 0 ) ;
26
28
} ) ;
27
29
}
28
30
@@ -99,17 +101,8 @@ async function handleUploadFiles(editor, dropzoneEl, files, e) {
99
101
const { width, dppx} = await imageInfo ( file ) ;
100
102
const placeholder = `[${ name } ](uploading ...)` ;
101
103
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 ) ) ;
113
106
editor . replacePlaceholder ( placeholder , generateMarkdownLinkForAttachment ( file , { width, dppx} ) ) ;
114
107
}
115
108
}
0 commit comments