@@ -113,44 +113,66 @@ const hasFiles = (): boolean => {
113113 return fileTabs .value .length > 0 ;
114114};
115115
116- const selectFile = (filePath : string ): void => {
116+ const waitForTabsUpdate = async (): Promise <void > => {
117+ // Wait a bit to ensure that the file tabs are properly updated.
118+ // Note: although a bit of a hack, this is needed when opening multiple files. Indeed, without this, the file tab may
119+ // not be fully initialised when opening the next file. This means that when we select the file tab, it may try
120+ // to finish initialising itself and, when it comes to our simulation experiment view, this means resizing the
121+ // plots.
122+
123+ await vue .nextTick ();
124+
125+ for (let i = 0 ; i < 3 ; ++ i ) {
126+ await common .waitForNextAnimationFrame ();
127+ }
128+ };
129+
130+ const selectFile = async (filePath : string , wait : boolean = false ): Promise <void > => {
117131 activeFile .value = filePath ;
132+
133+ if (wait ) {
134+ await waitForTabsUpdate ();
135+ }
118136};
119137
120- const selectNextFile = (): void => {
138+ const selectNextFile = async (): Promise < void > => {
121139 const fileTabIndex = fileTabs .value .findIndex ((fileTab ) => fileTab .file .path () === activeFile .value );
122140 const fileTabName = fileTabs .value [(fileTabIndex + 1 ) % fileTabs .value .length ]?.file .path () || ' ' ;
123141
124142 if (fileTabName !== ' ' ) {
125- selectFile (fileTabName );
143+ await selectFile (fileTabName );
126144 }
127145};
128146
129- const selectPreviousFile = (): void => {
147+ const selectPreviousFile = async (): Promise < void > => {
130148 const fileTabIndex = fileTabs .value .findIndex ((fileTab ) => fileTab .file .path () === activeFile .value );
131149 const fileTabName =
132150 fileTabs .value [(fileTabIndex - 1 + fileTabs .value .length ) % fileTabs .value .length ]?.file .path () || ' ' ;
133151
134152 if (fileTabName !== ' ' ) {
135- selectFile (fileTabName );
153+ await selectFile (fileTabName );
136154 }
137155};
138156
139- const openFile = (file : locApi .File ): void => {
157+ const openFile = async (file : locApi .File , wait : boolean = false ): Promise < void > => {
140158 const filePath = file .path ();
141159 const prevActiveFile = activeFile .value ;
142160
143- selectFile (filePath );
161+ await selectFile (filePath );
144162
145163 fileTabs .value .splice (fileTabs .value .findIndex ((fileTab ) => fileTab .file .path () === prevActiveFile ) + 1 , 0 , {
146164 file: file ,
147165 uiJson: file .uiJson ()
148166 });
149167
150168 electronApi ?.fileOpened (filePath );
169+
170+ if (wait ) {
171+ await waitForTabsUpdate ();
172+ }
151173};
152174
153- const closeFile = (filePath : string ): void => {
175+ const closeFile = async (filePath : string ): Promise < void > => {
154176 locApi .fileManager .unmanage (filePath );
155177
156178 const fileTabIndex = fileTabs .value .findIndex ((fileTab ) => fileTab .file .path () === filePath );
@@ -161,20 +183,20 @@ const closeFile = (filePath: string): void => {
161183 const nextFileTab = fileTabs .value [Math .min (fileTabIndex , fileTabs .value .length - 1 )];
162184
163185 if (nextFileTab ) {
164- selectFile (nextFileTab .file .path ());
186+ await selectFile (nextFileTab .file .path ());
165187 }
166188 }
167189
168190 electronApi ?.fileClosed (filePath );
169191};
170192
171- const closeCurrentFile = (): void => {
172- closeFile (activeFile .value );
193+ const closeCurrentFile = async (): Promise < void > => {
194+ await closeFile (activeFile .value );
173195};
174196
175- const closeAllFiles = (): void => {
197+ const closeAllFiles = async (): Promise < void > => {
176198 while (fileTabs .value .length ) {
177- closeCurrentFile ();
199+ await closeCurrentFile ();
178200 }
179201};
180202
0 commit comments