import com.intellij.openapi.actionSystem.Presentation;
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.util.DocumentUtil;
import com.jetbrains.edu.learning.StudyUtils;
import com.jetbrains.edu.learning.core.EduUtils;
import com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder;
placeholder.getActiveSubtaskInfo().setNeedInsertText(visible);
int length = isVisible() ? placeholder.getTaskText().length() : 0;
placeholder.setLength(length);
+ saveIndent(placeholder, state, !visible);
StudyUtils.drawAllWindows(state.getEditor(), state.getTaskFile());
}
+ private static void saveIndent(AnswerPlaceholder placeholder, CCState state, boolean visible) {
+ Document document = state.getEditor().getDocument();
+ int offset = placeholder.getOffset();
+ int lineNumber = document.getLineNumber(offset);
+ int nonSpaceCharOffset = DocumentUtil.getFirstNonSpaceCharOffset(document, lineNumber);
+ int newOffset = offset;
+ int endOffset = offset + placeholder.getRealLength();
+ if (!visible && nonSpaceCharOffset == offset) {
+ newOffset = document.getLineStartOffset(lineNumber);
+ }
+ if (visible) {
+ newOffset = DocumentUtil.getFirstNonSpaceCharOffset(document, offset, endOffset);
+ }
+ placeholder.setOffset(newOffset);
+ int delta = offset - newOffset;
+ placeholder.setPossibleAnswer(document.getText(TextRange.create(newOffset, newOffset + delta + placeholder.getRealLength())));
+ }
+
protected abstract String getName();
protected abstract boolean isVisible();
import com.intellij.openapi.project.Project;
import com.intellij.ui.JBColor;
import com.intellij.ui.SimpleTextAttributes;
+import com.intellij.util.DocumentUtil;
import com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder;
+import com.jetbrains.edu.learning.courseFormat.AnswerPlaceholderSubtaskInfo;
import com.jetbrains.edu.learning.courseFormat.TaskFile;
import org.jetbrains.annotations.NotNull;
@NotNull final JBColor color) {
EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
final TextAttributes textAttributes = new TextAttributes(scheme.getDefaultForeground(), scheme.getDefaultBackground(), null,
- EffectType.BOXED, Font.PLAIN);
+ EffectType.BOXED, Font.PLAIN);
textAttributes.setEffectColor(color);
if (placeholder.isActive()) {
drawAnswerPlaceholder(editor, placeholder, textAttributes, PLACEHOLDERS_LAYER);
@NotNull AnswerPlaceholder placeholder,
TextAttributes textAttributes,
int placeholdersLayer) {
- final int startOffset = placeholder.getOffset();
- if (startOffset == - 1) {
+ int startOffset = placeholder.getOffset();
+ if (startOffset == -1) {
return;
}
final int length = placeholder.getRealLength();
- final int endOffset = startOffset + length;
+ int delta = 0;
+ AnswerPlaceholderSubtaskInfo info = placeholder.getActiveSubtaskInfo();
+ if (info != null && info.isNeedInsertText()) {
+ Document document = editor.getDocument();
+ int nonSpaceCharOffset = DocumentUtil.getFirstNonSpaceCharOffset(document, startOffset, startOffset + length);
+ if (nonSpaceCharOffset != startOffset) {
+ delta = startOffset - nonSpaceCharOffset;
+ startOffset = nonSpaceCharOffset;
+ }
+ }
+ final int endOffset = startOffset + length + delta;
drawAnswerPlaceholder(editor, startOffset, endOffset, textAttributes, placeholdersLayer);
}
int placeholdersLayer) {
final Project project = editor.getProject();
assert project != null;
- if (start == - 1) {
+ if (start == -1) {
return;
}
RangeHighlighter
}
-
public static void drawAnswerPlaceholderFromPrevStep(@NotNull Editor editor, int start, int end) {
EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
Color color = scheme.getColor(EditorColors.TEARLINE_COLOR);
}
}
}
-
}