Skip to content

Commit 75f5c13

Browse files
authored
fix: Syntax highlighting and incorrect file display on multi-editor challenges (#1425)
* fix: Syntax highlighting and incorrect file display on multi-editor challenges * fix: rename initiateFile to initFile and streamline file initialization logic * fix: streamline file content retrieval in ChallengeViewModel * fix: update file retrieval method in ChallengeViewModel for improved accuracy
1 parent d355ad7 commit 75f5c13

File tree

2 files changed

+21
-27
lines changed

2 files changed

+21
-27
lines changed

mobile-app/lib/ui/views/learn/challenge/challenge_view.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class ChallengeView extends StatelessWidget {
5151
options: options,
5252
);
5353

54-
model.initiateFile(editor, challenge, currFile, editableRegion);
54+
model.initFile(editor, challenge, currFile, editableRegion);
5555
model.listenToFocusedController(editor);
5656
model.listenToSymbolBarScrollController();
5757

@@ -62,9 +62,7 @@ class ChallengeView extends StatelessWidget {
6262
editor.onTextChange.stream.listen((text) {
6363
model.fileService.saveFileInCache(
6464
challenge,
65-
model.currentSelectedFile != ''
66-
? model.currentSelectedFile
67-
: challenge.files[0].name,
65+
model.currentSelectedFile,
6866
text,
6967
);
7068

mobile-app/lib/ui/views/learn/challenge/challenge_viewmodel.dart

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -233,45 +233,28 @@ class ChallengeViewModel extends BaseViewModel {
233233
setupDialogUi();
234234

235235
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-
257236
setBlock = block;
258237
setChallengesCompleted = challengesCompleted;
259238
}
260239

261-
void initiateFile(
240+
void initFile(
262241
Editor editor,
263242
Challenge challenge,
264243
ChallengeFile currFile,
265244
bool hasRegion,
266245
) async {
267246
if (!_mounted) {
268247
await Future.delayed(Duration.zero);
248+
String fileContents = await fileService.getExactFileFromCache(
249+
challenge,
250+
currFile,
251+
);
269252
editor.fileTextStream.sink.add(
270253
FileIDE(
271254
id: challenge.id + currFile.name,
272255
ext: currFile.ext.name,
273256
name: currFile.name,
274-
content: editorText ?? currFile.contents,
257+
content: fileContents,
275258
hasRegion: hasRegion,
276259
region: EditorRegionOptions(
277260
start: hasRegion ? currFile.editableRegionBoundaries[0] : null,
@@ -281,6 +264,11 @@ class ChallengeViewModel extends BaseViewModel {
281264
),
282265
);
283266
_mounted = true;
267+
268+
if (currFile.name != currentSelectedFile) {
269+
setCurrentSelectedFile = currFile.name;
270+
setEditorText = fileContents;
271+
}
284272
}
285273
}
286274

@@ -427,6 +415,14 @@ class ChallengeViewModel extends BaseViewModel {
427415
return file;
428416
}
429417

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+
430426
return challenge.files[0];
431427
}
432428

0 commit comments

Comments
 (0)