@@ -233,45 +233,28 @@ class ChallengeViewModel extends BaseViewModel {
233
233
setupDialogUi ();
234
234
235
235
setChallenge = challenge;
236
-
237
- List <ChallengeFile > currentEditedChallenge = challenge.files
238
- .where ((element) => element.editableRegionBoundaries.isNotEmpty)
239
- .toList ();
240
-
241
- if (editorText == null ) {
242
- String text = await fileService.getExactFileFromCache (
243
- challenge,
244
- currentEditedChallenge.isEmpty
245
- ? challenge.files.first
246
- : currentEditedChallenge.first,
247
- );
248
-
249
- if (text != '' ) {
250
- setEditorText = text;
251
- }
252
- }
253
- setCurrentSelectedFile = currentEditedChallenge.isEmpty
254
- ? challenge.files[0 ].name
255
- : currentEditedChallenge[0 ].name;
256
-
257
236
setBlock = block;
258
237
setChallengesCompleted = challengesCompleted;
259
238
}
260
239
261
- void initiateFile (
240
+ void initFile (
262
241
Editor editor,
263
242
Challenge challenge,
264
243
ChallengeFile currFile,
265
244
bool hasRegion,
266
245
) async {
267
246
if (! _mounted) {
268
247
await Future .delayed (Duration .zero);
248
+ String fileContents = await fileService.getExactFileFromCache (
249
+ challenge,
250
+ currFile,
251
+ );
269
252
editor.fileTextStream.sink.add (
270
253
FileIDE (
271
254
id: challenge.id + currFile.name,
272
255
ext: currFile.ext.name,
273
256
name: currFile.name,
274
- content: editorText ?? currFile.contents ,
257
+ content: fileContents ,
275
258
hasRegion: hasRegion,
276
259
region: EditorRegionOptions (
277
260
start: hasRegion ? currFile.editableRegionBoundaries[0 ] : null ,
@@ -281,6 +264,11 @@ class ChallengeViewModel extends BaseViewModel {
281
264
),
282
265
);
283
266
_mounted = true ;
267
+
268
+ if (currFile.name != currentSelectedFile) {
269
+ setCurrentSelectedFile = currFile.name;
270
+ setEditorText = fileContents;
271
+ }
284
272
}
285
273
}
286
274
@@ -427,6 +415,14 @@ class ChallengeViewModel extends BaseViewModel {
427
415
return file;
428
416
}
429
417
418
+ List <ChallengeFile >? fileWithEditableRegion = challenge.files
419
+ .where ((file) => file.editableRegionBoundaries.isNotEmpty)
420
+ .toList ();
421
+
422
+ if (fileWithEditableRegion.isNotEmpty) {
423
+ return fileWithEditableRegion[0 ];
424
+ }
425
+
430
426
return challenge.files[0 ];
431
427
}
432
428
0 commit comments