save indent for task text
authorLiana.Bakradze <liana.bakradze@jetbrains.com>
Thu, 27 Oct 2016 13:55:43 +0000 (16:55 +0300)
committerliana.bakradze <liana.bakradze@jetbrains.com>
Thu, 17 Nov 2016 14:08:36 +0000 (17:08 +0300)
python/educational-core/course-creator/src/com/jetbrains/edu/coursecreator/actions/placeholder/CCChangePlaceholderVisibility.java

index 9c56d0bd432c5555c87cf4b3ef1cc97cf451fd9f..eb0c7dfde710dbb0bea5935baf25cd3f86f1bf16 100644 (file)
@@ -6,6 +6,7 @@ import com.intellij.openapi.command.undo.BasicUndoableAction;
 import com.intellij.openapi.command.undo.UnexpectedUndoException;
 import com.intellij.openapi.editor.Document;
 import com.intellij.openapi.util.TextRange;
 import com.intellij.openapi.command.undo.UnexpectedUndoException;
 import com.intellij.openapi.editor.Document;
 import com.intellij.openapi.util.TextRange;
+import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.util.DocumentUtil;
 import com.jetbrains.edu.learning.StudyUtils;
 import com.jetbrains.edu.learning.core.EduUtils;
 import com.intellij.util.DocumentUtil;
 import com.jetbrains.edu.learning.StudyUtils;
 import com.jetbrains.edu.learning.core.EduUtils;
@@ -43,9 +44,9 @@ public abstract class CCChangePlaceholderVisibility extends CCAnswerPlaceholderA
 
   private void setVisible(AnswerPlaceholder placeholder, boolean visible, CCState state) {
     placeholder.getActiveSubtaskInfo().setNeedInsertText(visible);
 
   private void setVisible(AnswerPlaceholder placeholder, boolean visible, CCState state) {
     placeholder.getActiveSubtaskInfo().setNeedInsertText(visible);
+    saveIndent(placeholder, state, !visible);
     int length = isVisible() ? placeholder.getTaskText().length() : 0;
     placeholder.setLength(length);
     int length = isVisible() ? placeholder.getTaskText().length() : 0;
     placeholder.setLength(length);
-    saveIndent(placeholder, state, !visible);
     StudyUtils.drawAllAnswerPlaceholders(state.getEditor(), state.getTaskFile());
   }
 
     StudyUtils.drawAllAnswerPlaceholders(state.getEditor(), state.getTaskFile());
   }
 
@@ -65,6 +66,14 @@ public abstract class CCChangePlaceholderVisibility extends CCAnswerPlaceholderA
     placeholder.setOffset(newOffset);
     int delta = offset - newOffset;
     placeholder.setPossibleAnswer(document.getText(TextRange.create(newOffset, newOffset + delta + placeholder.getRealLength())));
     placeholder.setOffset(newOffset);
     int delta = offset - newOffset;
     placeholder.setPossibleAnswer(document.getText(TextRange.create(newOffset, newOffset + delta + placeholder.getRealLength())));
+    String oldTaskText = placeholder.getTaskText();
+    if (delta >= 0) {
+      placeholder.setTaskText(StringUtil.repeat(" ", delta) + oldTaskText);
+    }
+    else {
+      String newTaskText = oldTaskText.substring(Math.abs(delta));
+      placeholder.setTaskText(newTaskText);
+    }
   }
 
   protected abstract String getName();
   }
 
   protected abstract String getName();