import com.jetbrains.edu.learning.StudyTaskManager;
import com.jetbrains.edu.learning.core.EduNames;
import com.jetbrains.edu.learning.core.EduUtils;
-import com.jetbrains.edu.learning.courseFormat.Course;
-import com.jetbrains.edu.learning.courseFormat.Lesson;
-import com.jetbrains.edu.learning.courseFormat.Task;
-import com.jetbrains.edu.learning.courseFormat.TaskFile;
+import com.jetbrains.edu.learning.courseFormat.*;
import org.jetbrains.annotations.NotNull;
import java.io.*;
private static void resetTaskFiles(Map<TaskFile, TaskFile> savedTaskFiles) {
for (Map.Entry<TaskFile, TaskFile> entry : savedTaskFiles.entrySet()) {
- entry.getKey().setAnswerPlaceholders(entry.getValue().getAnswerPlaceholders());
+ List<AnswerPlaceholder> placeholders = entry.getValue().getAnswerPlaceholders();
+ for (AnswerPlaceholder placeholder : placeholders) {
+ placeholder.setUseLength(false);
+ }
+ entry.getKey().setAnswerPlaceholders(placeholders);
}
}
if (document == null) {
continue;
}
- if (!answerPlaceholder.isValid(document)) {
- continue;
- }
StudySmartChecker.smartCheck(answerPlaceholder, project, answerFile, answerTaskFile, taskFile, testRunner,
virtualFile, document);
}
EduDocumentListener listener = new EduDocumentListener(target);
document.addDocumentListener(listener);
for (AnswerPlaceholder answerPlaceholder : target.getAnswerPlaceholders()) {
- if (!answerPlaceholder.isValid(document)) {
- continue;
- }
final int start = answerPlaceholder.getOffset();
final int end = start + answerPlaceholder.getRealLength();
final String text = answerPlaceholder.getPossibleAnswer();
public static void drawAnswerPlaceholder(@NotNull final Editor editor, @NotNull final AnswerPlaceholder placeholder,
@NotNull final JBColor color) {
- final Document document = editor.getDocument();
- if (!placeholder.isValid(document)) {
- return;
- }
EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
final TextAttributes textAttributes = new TextAttributes(scheme.getDefaultForeground(), scheme.getDefaultBackground(), null,
EffectType.BOXED, Font.PLAIN);
if (document instanceof DocumentImpl) {
DocumentImpl documentImpl = (DocumentImpl)document;
List<RangeMarker> blocks = documentImpl.getGuardedBlocks();
- if (!placeholder.isValid(document)) return;
int start = placeholder.getOffset();
final int length = placeholder.getRealLength();
int end = start + length;
AnswerPlaceholder answerPlaceholder = answerPlaceholderWrapper.getAnswerPlaceholder();
int length = twEnd - twStart;
answerPlaceholder.setOffset(twStart);
- answerPlaceholder.setLength(length);
if (!answerPlaceholder.getUseLength()) {
answerPlaceholder.setPossibleAnswer(document.getText(TextRange.create(twStart, twStart + length)));
}
printWriter = new PrintWriter(new FileOutputStream(fileWindows.getPath()));
for (AnswerPlaceholder answerPlaceholder : taskFile.getAnswerPlaceholders()) {
int length = answerPlaceholder.getRealLength();
- if (!answerPlaceholder.isValid(document, length)) {
- printWriter.println("#educational_plugin_window = ");
- continue;
- }
int start = answerPlaceholder.getOffset();
final String windowDescription = document.getText(new TextRange(start, start + length));
printWriter.println("#educational_plugin_window = " + windowDescription);
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
-import com.intellij.openapi.editor.Document;
import com.intellij.util.xmlb.annotations.Transient;
-import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
return possibleAnswer.length();
}
- public boolean isValid(@NotNull final Document document) {
- return isValid(document, length);
- }
-
- public boolean isValid(@NotNull final Document document, int length) {
- return myOffset >= 0 && myOffset + length <= document.getTextLength();
- }
-
/**
* Returns window to its initial state
*/
}
public static void navigateToAnswerPlaceholder(@NotNull final Editor editor, @NotNull final AnswerPlaceholder answerPlaceholder) {
- if (editor.isDisposed() || !answerPlaceholder.isValid(editor.getDocument())) {
+ if (editor.isDisposed()) {
return;
}
editor.getCaretModel().moveToOffset(answerPlaceholder.getOffset());