EDU-463 Select the first answer placeholder on Go to Next task action
authorLiana Bakradze <liana.bakradze@jetbrains.com>
Mon, 14 Sep 2015 10:35:57 +0000 (13:35 +0300)
committerLiana Bakradze <liana.bakradze@jetbrains.com>
Mon, 14 Sep 2015 10:42:59 +0000 (13:42 +0300)
python/educational/interactive-learning/src/com/jetbrains/edu/learning/courseGeneration/StudyProjectGenerator.java
python/educational/interactive-learning/src/com/jetbrains/edu/learning/editor/StudyEditorFactoryListener.java

index 6003caf33b4a1659be7a678a510fdef9bda15116..f35243485a8fd90f626e4850b547a999c192fae4 100644 (file)
@@ -141,6 +141,7 @@ public class StudyProjectGenerator {
     if (activeVirtualFile != null) {
       final PsiFile file = PsiManager.getInstance(project).findFile(activeVirtualFile);
       ProjectView.getInstance(project).select(file, activeVirtualFile, true);
+      FileEditorManager.getInstance(project).openFile(activeVirtualFile, true);
     } else {
       String first = StudyUtils.getFirst(taskFiles.keySet());
       if (first != null) {
index 37fbd9ada83231e1b075c18dfc0a68486a141b58..1c8ffe4270bd1dfd839962aa48508b56d7246be6 100644 (file)
@@ -32,8 +32,9 @@ public class StudyEditorFactoryListener implements EditorFactoryListener {
     private final TaskFile myTaskFile;
     private AnswerPlaceholder myAnswerPlaceholderWithSelection;
 
-    WindowSelectionListener(@NotNull final TaskFile taskFile) {
+    WindowSelectionListener(@NotNull final TaskFile taskFile, AnswerPlaceholder placeholder) {
       myTaskFile = taskFile;
+      myAnswerPlaceholderWithSelection = placeholder;
     }
 
     @Override
@@ -75,17 +76,21 @@ public class StudyEditorFactoryListener implements EditorFactoryListener {
               if (openedFile != null) {
                 final TaskFile taskFile = StudyUtils.getTaskFile(project, openedFile);
                 if (taskFile != null) {
-                  StudyNavigator.navigateToFirstAnswerPlaceholder(editor, taskFile);
-                  StudyEditor.addDocumentListener(document, new EduDocumentListener(taskFile));
                   WolfTheProblemSolver.getInstance(project).clearProblems(openedFile);
-                  StudyUtils.drawAllWindows(editor, taskFile);
-                  editor.addEditorMouseListener(new WindowSelectionListener(taskFile));
                   final ToolWindow studyToolWindow = ToolWindowManager.getInstance(project).getToolWindow(StudyToolWindowFactory.STUDY_TOOL_WINDOW);
                   if (studyToolWindow != null) {
                     StudyUtils.updateToolWindows(project);
                     studyToolWindow.show(null);
                   }
-
+                  if (!taskFile.getAnswerPlaceholders().isEmpty()) {
+                    StudyNavigator.navigateToFirstAnswerPlaceholder(editor, taskFile);
+                    StudyEditor.addDocumentListener(document, new EduDocumentListener(taskFile));
+                    StudyUtils.drawAllWindows(editor, taskFile);
+                    AnswerPlaceholder first = StudyUtils.getFirst(taskFile.getAnswerPlaceholders());
+                    int offset = first.getRealStartOffset(document);
+                    editor.getSelectionModel().setSelection(offset, offset + first.getLength());
+                    editor.addEditorMouseListener(new WindowSelectionListener(taskFile, first));
+                  }
                 }
               }
             }