diff --git a/shared/src/commonMain/kotlin/org/hyperskill/app/step_quiz_code_blanks/domain/model/template/CodeBlanksTemplateMapper.kt b/shared/src/commonMain/kotlin/org/hyperskill/app/step_quiz_code_blanks/domain/model/template/CodeBlanksTemplateMapper.kt index ec0d157dd..cfc1d3bb7 100644 --- a/shared/src/commonMain/kotlin/org/hyperskill/app/step_quiz_code_blanks/domain/model/template/CodeBlanksTemplateMapper.kt +++ b/shared/src/commonMain/kotlin/org/hyperskill/app/step_quiz_code_blanks/domain/model/template/CodeBlanksTemplateMapper.kt @@ -30,14 +30,11 @@ internal object CodeBlanksTemplateMapper { private fun mapCodeBlanksTemplate( codeBlanksTemplate: List, step: Step - ): List { - val supportedEntries = codeBlanksTemplate.filter { it.type != CodeBlockTemplateEntryType.UNKNOWN } - return if (supportedEntries.isEmpty()) { - emptyList() - } else { - supportedEntries.map { mapCodeBlockTemplateEntry(entry = it, step = step) } - } - } + ): List = + codeBlanksTemplate + .filter { it.type != CodeBlockTemplateEntryType.UNKNOWN } + .map { mapCodeBlockTemplateEntry(entry = it, step = step) } + .let { setSuggestionsForBlankCodeBlocks(codeBlocks = it, step = step) } private fun mapCodeBlockTemplateEntry( entry: CodeBlockTemplateEntry, @@ -49,10 +46,7 @@ internal object CodeBlanksTemplateMapper { isActive = entry.isActive, indentLevel = entry.indentLevel, isDeleteForbidden = entry.isDeleteForbidden, - suggestions = StepQuizCodeBlanksResolver.getSuggestionsForBlankCodeBlock( - isVariableSuggestionAvailable = StepQuizCodeBlanksResolver.isVariableSuggestionsAvailable(step), - availableConditions = step.block.options.codeBlanksAvailableConditions ?: emptySet() - ) + suggestions = emptyList() ) CodeBlockTemplateEntryType.PRINT -> CodeBlock.Print( @@ -140,6 +134,26 @@ internal object CodeBlanksTemplateMapper { } } + private fun setSuggestionsForBlankCodeBlocks( + codeBlocks: List, + step: Step + ): List = + codeBlocks.mapIndexed { index, codeBlock -> + if (codeBlock is CodeBlock.Blank) { + codeBlock.copy( + suggestions = StepQuizCodeBlanksResolver.getSuggestionsForBlankCodeBlock( + index = index, + indentLevel = codeBlock.indentLevel, + codeBlocks = codeBlocks, + isVariableSuggestionAvailable = StepQuizCodeBlanksResolver.isVariableSuggestionsAvailable(step), + availableConditions = step.block.options.codeBlanksAvailableConditions ?: emptySet() + ) + ) + } else { + codeBlock + } + } + private fun createMathExpressionsCodeBlocks(step: Step): List = listOf( CodeBlock.Variable( diff --git a/shared/src/commonMain/kotlin/org/hyperskill/app/step_quiz_code_blanks/presentation/StepQuizCodeBlanksResolver.kt b/shared/src/commonMain/kotlin/org/hyperskill/app/step_quiz_code_blanks/presentation/StepQuizCodeBlanksResolver.kt index ecc0a2a8b..f0b629948 100644 --- a/shared/src/commonMain/kotlin/org/hyperskill/app/step_quiz_code_blanks/presentation/StepQuizCodeBlanksResolver.kt +++ b/shared/src/commonMain/kotlin/org/hyperskill/app/step_quiz_code_blanks/presentation/StepQuizCodeBlanksResolver.kt @@ -44,7 +44,11 @@ internal object StepQuizCodeBlanksResolver { } else -> - listOf(Suggestion.Print) + if (availableConditions.contains(Suggestion.IfStatement.text)) { + listOf(Suggestion.Print, Suggestion.IfStatement) + } else { + listOf(Suggestion.Print) + } } fun areElifAndElseStatementsSuggestionsAvailable(