@@ -526,7 +526,7 @@ function store(state, emitter) {
526
526
let contents = cleanCharacters ( editor . getValue ( ) )
527
527
editor . setValue ( contents )
528
528
529
- if ( state . selectedDevice === 'serial' ) {
529
+ if ( state . isConnected && state . selectedDevice === 'serial' ) {
530
530
// Ask for confirmation to overwrite existing file
531
531
let confirmation = true
532
532
if ( state . serialFiles . find ( f => f . path === filename ) ) {
@@ -535,6 +535,11 @@ function store(state, emitter) {
535
535
536
536
if ( confirmation ) {
537
537
emitter . emit ( 'message' , `Saving ${ filename } on ${ deviceName } .` )
538
+ const newPath = serial . getFullPath (
539
+ state . serialPath ,
540
+ state . serialNavigation ,
541
+ filename
542
+ )
538
543
if ( state . serialFiles . find ( f => f . path === oldFilename ) ) {
539
544
const oldPath = serial . getFullPath (
540
545
state . serialPath ,
@@ -547,20 +552,8 @@ function store(state, emitter) {
547
552
contents ,
548
553
( e ) => emitter . emit ( 'message' , `Saving ${ filename } on ${ deviceName } . ${ e } ` )
549
554
)
550
- await serial . renameFile (
551
- oldPath ,
552
- serial . getFullPath (
553
- state . serialPath ,
554
- state . serialNavigation ,
555
- filename
556
- )
557
- )
555
+ await serial . renameFile ( oldPath , newPath )
558
556
} else {
559
- const newPath = serial . getFullPath (
560
- state . serialPath ,
561
- state . serialNavigation ,
562
- filename
563
- )
564
557
// If old name doesn't exist create new file
565
558
await serial . saveFileContent (
566
559
newPath ,
@@ -587,38 +580,23 @@ function store(state, emitter) {
587
580
}
588
581
if ( confirmation ) {
589
582
emitter . emit ( 'message' , `Renaming` )
583
+ const newPath = disk . getFullPath (
584
+ state . diskPath ,
585
+ state . diskNavigation ,
586
+ filename
587
+ )
590
588
if ( state . diskFiles . find ( ( f ) => f . path === oldFilename ) ) {
591
589
// If old name exists, save old file and rename
592
- await disk . saveFileContent (
593
- disk . getFullPath (
594
- state . diskPath ,
595
- state . diskNavigation ,
596
- oldFilename
597
- ) ,
598
- contents
599
- )
600
- await disk . renameFile (
601
- disk . getFullPath (
602
- state . diskPath ,
603
- state . diskNavigation ,
604
- oldFilename
605
- ) ,
606
- disk . getFullPath (
607
- state . diskPath ,
608
- state . diskNavigation ,
609
- filename
610
- )
590
+ const oldPath = disk . getFullPath (
591
+ state . diskPath ,
592
+ state . diskNavigation ,
593
+ oldFilename
611
594
)
595
+ await disk . saveFileContent ( oldPath , contents )
596
+ await disk . renameFile ( oldPath , newPath )
612
597
} else {
613
598
// If old name doesn't exist create new file
614
- await disk . saveFileContent (
615
- disk . getFullPath (
616
- state . diskPath ,
617
- state . diskNavigation ,
618
- filename
619
- ) ,
620
- contents
621
- )
599
+ await disk . saveFileContent ( newPath , contents )
622
600
}
623
601
state . isEditingFilename = false
624
602
emitter . emit ( 'message' , `Saved` , 500 )
0 commit comments