@@ -163,6 +163,7 @@ export class PreviewModel implements ViewModel {
163
163
connectionError : PrimitiveAtom < string > ;
164
164
165
165
openFileModal : PrimitiveAtom < boolean > ;
166
+ openFileModalDelay : PrimitiveAtom < boolean > ;
166
167
openFileError : PrimitiveAtom < string > ;
167
168
openFileModalGiveFocusRef : React . MutableRefObject < ( ) => boolean > ;
168
169
@@ -185,6 +186,7 @@ export class PreviewModel implements ViewModel {
185
186
this . refreshVersion = atom ( 0 ) ;
186
187
this . previewTextRef = createRef ( ) ;
187
188
this . openFileModal = atom ( false ) ;
189
+ this . openFileModalDelay = atom ( false ) ;
188
190
this . openFileError = atom ( null ) as PrimitiveAtom < string > ;
189
191
this . openFileModalGiveFocusRef = createRef ( ) ;
190
192
this . manageConnection = atom ( true ) ;
@@ -252,7 +254,7 @@ export class PreviewModel implements ViewModel {
252
254
text : headerPath ,
253
255
ref : this . previewTextRef ,
254
256
className : "preview-filename" ,
255
- onClick : ( ) => this . updateOpenFileModalAndError ( true ) ,
257
+ onClick : ( ) => this . toggleOpenFileModal ( ) ,
256
258
} ,
257
259
] ;
258
260
let saveClassName = "grey" ;
@@ -537,6 +539,25 @@ export class PreviewModel implements ViewModel {
537
539
updateOpenFileModalAndError ( isOpen , errorMsg = null ) {
538
540
globalStore . set ( this . openFileModal , isOpen ) ;
539
541
globalStore . set ( this . openFileError , errorMsg ) ;
542
+ if ( isOpen ) {
543
+ globalStore . set ( this . openFileModalDelay , true ) ;
544
+ } else {
545
+ const delayVal = globalStore . get ( this . openFileModalDelay ) ;
546
+ if ( delayVal ) {
547
+ setTimeout ( ( ) => {
548
+ globalStore . set ( this . openFileModalDelay , false ) ;
549
+ } , 200 ) ;
550
+ }
551
+ }
552
+ }
553
+
554
+ toggleOpenFileModal ( ) {
555
+ const modalOpen = globalStore . get ( this . openFileModal ) ;
556
+ const delayVal = globalStore . get ( this . openFileModalDelay ) ;
557
+ if ( ! modalOpen && delayVal ) {
558
+ return ;
559
+ }
560
+ this . updateOpenFileModalAndError ( ! modalOpen ) ;
540
561
}
541
562
542
563
async goHistory ( newPath : string ) {
@@ -811,12 +832,9 @@ export class PreviewModel implements ViewModel {
811
832
fireAndForget ( ( ) => this . goParentDirectory ( { } ) ) ;
812
833
return true ;
813
834
}
814
- const openModalOpen = globalStore . get ( this . openFileModal ) ;
815
- if ( ! openModalOpen ) {
816
- if ( checkKeyPressed ( e , "Cmd:o" ) ) {
817
- this . updateOpenFileModalAndError ( true ) ;
818
- return true ;
819
- }
835
+ if ( checkKeyPressed ( e , "Cmd:o" ) ) {
836
+ this . toggleOpenFileModal ( ) ;
837
+ return true ;
820
838
}
821
839
const canPreview = globalStore . get ( this . canPreview ) ;
822
840
if ( canPreview ) {
@@ -1066,7 +1084,6 @@ const SpecializedView = memo(({ parentRef, model }: SpecializedViewProps) => {
1066
1084
if ( ! SpecializedViewComponent ) {
1067
1085
return < CenteredDiv > Invalid Specialzied View Component ({ specializedView . specializedView } )</ CenteredDiv > ;
1068
1086
}
1069
- console . log ( "RENDER AGAIN SpecializedView" , model , parentRef ) ;
1070
1087
return < SpecializedViewComponent model = { model } parentRef = { parentRef } /> ;
1071
1088
} ) ;
1072
1089
0 commit comments