show preview for subtasks
[idea/community.git] / python / educational-core / student / src / com / jetbrains / edu / learning / core / EduUtils.java
index 6a7bb8c1b3e64e06898320e1629af07770f36115..2d225567eba0ab48bfbbfb2289265d0b734d30c5 100644 (file)
@@ -20,6 +20,7 @@ import com.intellij.openapi.vfs.VfsUtilCore;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.openapi.vfs.VirtualFileManager;
 import com.intellij.psi.PsiDirectory;
+import com.intellij.util.containers.ContainerUtil;
 import com.jetbrains.edu.learning.StudyUtils;
 import com.jetbrains.edu.learning.courseFormat.*;
 import org.jetbrains.annotations.NonNls;
@@ -164,6 +165,14 @@ public class EduUtils {
     studentDocument.addDocumentListener(listener);
 
     for (AnswerPlaceholder placeholder : taskFile.getActivePlaceholders()) {
+      Set<Integer> indexes = placeholder.getSubtaskInfos().keySet();
+      int activeSubtaskIndex = task.getActiveSubtaskIndex();
+      if (Collections.min(indexes) < activeSubtaskIndex) {
+        Integer max = Collections.max(ContainerUtil.filter(indexes, i -> i < activeSubtaskIndex));
+        String possibleAnswer = placeholder.getSubtaskInfos().get(max).getPossibleAnswer();
+        replaceAnswerPlaceholder(project, studentDocument, placeholder, placeholder.getRealLength(), possibleAnswer);
+        continue;
+      }
       replaceAnswerPlaceholder(project, studentDocument, placeholder, placeholder.getRealLength(), placeholder.getTaskText());
     }
     studentDocument.removeDocumentListener(listener);