@@ -441,26 +441,18 @@ function store(state, emitter) {
441
441
442
442
if ( confirmation ) {
443
443
if ( state . serialFiles . find ( f => f . path === oldFilename ) ) {
444
+ const oldPath = cleanPath ( state . serialNavigation + '/' + oldFilename )
444
445
// If old name exists, save old file and rename
445
- await serial . saveFileContent (
446
- cleanPath ( state . serialNavigation + '/' + oldFilename ) ,
447
- contents
448
- )
449
- await serial . renameFile (
450
- cleanPath ( state . serialNavigation + '/' + oldFilename ) ,
451
- filename
452
- )
446
+ await serial . saveFileContent ( oldPath , contents )
447
+ await serial . renameFile ( oldPath , filename )
453
448
} else {
449
+ const newPath = cleanPath ( state . serialNavigation + '/' + filename )
454
450
// If old name doesn't exist create new file
455
- await serial . saveFileContent (
456
- cleanPath ( state . serialNavigation + '/' + filename ) ,
457
- contents
458
- )
451
+ // First create an empty file
452
+ await serial . saveFileContent ( newPath , '' )
453
+ await serial . saveFileContent ( newPath , contents )
459
454
}
460
455
state . isEditingFilename = false
461
- emitter . emit ( 'update-files' )
462
- emitter . emit ( 'render' )
463
-
464
456
emitter . emit ( 'message' , `Saved` , 500 )
465
457
} else {
466
458
state . selectedFile = oldFilename
@@ -471,6 +463,7 @@ function store(state, emitter) {
471
463
}
472
464
473
465
if ( state . diskPath !== null && state . selectedDevice === 'disk' ) {
466
+ const diskPath = cleanPath ( state . diskPath + '/' + state . diskNavigation )
474
467
// Ask for confirmation to overwrite existing file
475
468
let confirmation = true
476
469
if ( state . diskFiles . find ( ( f ) => f . path === filename ) ) {
@@ -479,38 +472,22 @@ function store(state, emitter) {
479
472
if ( confirmation ) {
480
473
if ( state . diskFiles . find ( ( f ) => f . path === oldFilename ) ) {
481
474
// If old name exists, save old file and rename
482
- await disk . saveFileContent (
483
- cleanPath ( state . diskPath + '/' + state . diskNavigation ) ,
484
- oldFilename ,
485
- contents
486
- )
487
- await disk . renameFile (
488
- cleanPath ( state . diskPath + '/' + state . diskNavigation ) ,
489
- oldFilename ,
490
- filename
491
- )
475
+ await disk . saveFileContent ( diskPath , oldFilename , contents )
476
+ await disk . renameFile ( diskPath , oldFilename , filename )
492
477
} else {
493
478
// If old name doesn't exist create new file
494
- await disk . saveFileContent (
495
- cleanPath ( state . diskPath + '/' + state . diskNavigation ) ,
496
- filename ,
497
- contents
498
- )
479
+ await disk . saveFileContent ( diskPath , filename , contents )
499
480
}
500
481
state . isEditingFilename = false
501
- emitter . emit ( 'update-files' )
502
- emitter . emit ( 'render' )
503
-
504
- // emitter.emit('message', `${filename} is saved on ${deviceName}.`, 1000)
505
- mitter . emit ( 'message' , `Saved` , 500 )
482
+ emitter . emit ( 'message' , `Saved` , 500 )
506
483
} else {
507
484
state . selectedFile = oldFilename
508
485
state . isEditingFilename = false
509
486
emitter . emit ( 'render' )
510
487
}
511
488
}
512
489
513
-
490
+ emitter . emit ( 'update-files' )
514
491
} )
515
492
516
493
// NAVIGATION
0 commit comments