Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions mobile-app/lib/ui/views/learn/challenge/challenge_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ChallengeView extends StatelessWidget {
options: options,
);

model.initiateFile(editor, challenge, currFile, editableRegion);
model.initFile(editor, challenge, currFile, editableRegion);
model.listenToFocusedController(editor);
model.listenToSymbolBarScrollController();

Expand All @@ -61,9 +61,7 @@ class ChallengeView extends StatelessWidget {
editor.onTextChange.stream.listen((text) {
model.fileService.saveFileInCache(
challenge,
model.currentSelectedFile != ''
? model.currentSelectedFile
: challenge.files[0].name,
model.currentSelectedFile,
text,
);

Expand Down
42 changes: 19 additions & 23 deletions mobile-app/lib/ui/views/learn/challenge/challenge_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -233,45 +233,28 @@ class ChallengeViewModel extends BaseViewModel {
setupDialogUi();

setChallenge = challenge;

List<ChallengeFile> currentEditedChallenge = challenge.files
.where((element) => element.editableRegionBoundaries.isNotEmpty)
.toList();

if (editorText == null) {
String text = await fileService.getExactFileFromCache(
challenge,
currentEditedChallenge.isEmpty
? challenge.files.first
: currentEditedChallenge.first,
);

if (text != '') {
setEditorText = text;
}
}
setCurrentSelectedFile = currentEditedChallenge.isEmpty
? challenge.files[0].name
: currentEditedChallenge[0].name;

setBlock = block;
setChallengesCompleted = challengesCompleted;
}

void initiateFile(
void initFile(
Editor editor,
Challenge challenge,
ChallengeFile currFile,
bool hasRegion,
) async {
if (!_mounted) {
await Future.delayed(Duration.zero);
String fileContents = await fileService.getExactFileFromCache(
challenge,
currFile,
);
editor.fileTextStream.sink.add(
FileIDE(
id: challenge.id + currFile.name,
ext: currFile.ext.name,
name: currFile.name,
content: editorText ?? currFile.contents,
content: fileContents,
hasRegion: hasRegion,
region: EditorRegionOptions(
start: hasRegion ? currFile.editableRegionBoundaries[0] : null,
Expand All @@ -281,6 +264,11 @@ class ChallengeViewModel extends BaseViewModel {
),
);
_mounted = true;

if (currFile.name != currentSelectedFile) {
setCurrentSelectedFile = currFile.name;
setEditorText = fileContents;
}
}
}

Expand Down Expand Up @@ -427,6 +415,14 @@ class ChallengeViewModel extends BaseViewModel {
return file;
}

List<ChallengeFile>? fileWithEditableRegion = challenge.files
.where((file) => file.editableRegionBoundaries.isNotEmpty)
.toList();

if (fileWithEditableRegion.isNotEmpty) {
return fileWithEditableRegion[0];
}

return challenge.files[0];
}

Expand Down
Loading