@@ -142,6 +142,7 @@ class FileDialog {
142142 async _openFolder ( path ) {
143143 const fileList = this . _currentModal . querySelector ( "#file-list" ) ;
144144 const okButton = this . _currentModal . querySelector ( "button.ok-button" ) ;
145+ const fileName = this . _currentModal . querySelector ( "#filename" ) ;
145146 this . _removeAllChildNodes ( fileList ) ;
146147 if ( path !== undefined ) {
147148 this . _currentPath = path ;
@@ -167,6 +168,7 @@ class FileDialog {
167168 } catch ( e ) {
168169 console . log ( e ) ;
169170 }
171+ fileName . value = "" ;
170172 okButton . disabled = true ;
171173 }
172174
@@ -218,26 +220,31 @@ class FileDialog {
218220
219221 async _openItem ( item ) {
220222 const fileNameField = this . _currentModal . querySelector ( "#filename" ) ;
223+ const fileList = this . _currentModal . querySelector ( "#file-list" ) ;
221224 let filetype , filename ;
225+ let selectedItem = null ;
226+
227+ // Loop through items and see if any have data-selected
228+ for ( let listItem of fileList . childNodes ) {
229+ if ( ( / t r u e / i) . test ( listItem . getAttribute ( "data-selected" ) ) ) {
230+ selectedItem = listItem ;
231+ }
232+ }
222233
223234 if ( item !== undefined ) {
224235 filetype = item . getAttribute ( "data-type" ) ;
225236 filename = item . querySelector ( "span" ) . innerHTML ;
226237 } else if ( this . _validFilename ( fileNameField . value ) ) {
227- filename = fileNameField . value ;
228- filetype = "text" ;
229- } else {
230- // Loop through items and see if any have data-selected
231- const fileList = this . _currentModal . querySelector ( "#file-list" ) ;
232- for ( let listItem of fileList . childNodes ) {
233- if ( ( / t r u e / i) . test ( listItem . getAttribute ( "data-selected" ) ) ) {
234- item = listItem ;
235- }
236- }
237- if ( item !== undefined ) {
238- filetype = item . getAttribute ( "data-type" ) ;
239- filename = item . querySelector ( "span" ) . innerHTML ;
238+ if ( selectedItem !== null && fileNameField . value != selectedItem . querySelector ( "span" ) . innerHTML ) {
239+ filetype = selectedItem . getAttribute ( "data-type" ) ;
240+ filename = selectedItem . querySelector ( "span" ) . innerHTML ;
241+ } else {
242+ filename = fileNameField . value ;
243+ filetype = "text" ;
240244 }
245+ } else if ( selectedItem !== null ) {
246+ filetype = selectedItem . getAttribute ( "data-type" ) ;
247+ filename = selectedItem . querySelector ( "span" ) . innerHTML ;
241248 }
242249
243250 if ( filename !== undefined && filetype !== undefined ) {
0 commit comments