1 package com.jetbrains.edu.learning;
3 import com.intellij.codeInsight.editorActions.TypedHandlerDelegate;
4 import com.intellij.codeInsight.hint.HintManager;
5 import com.intellij.openapi.editor.Editor;
6 import com.intellij.openapi.fileTypes.FileType;
7 import com.intellij.openapi.project.Project;
8 import com.intellij.psi.PsiFile;
9 import com.jetbrains.edu.learning.courseFormat.TaskFile;
10 import org.jetbrains.annotations.NotNull;
12 public class StudyTypeHandlerDelegate extends TypedHandlerDelegate {
15 public Result checkAutoPopup(char charTyped, Project project, Editor editor, PsiFile file) {
16 return handleTyping(project, editor, file);
20 public Result beforeCharTyped(char c,
25 return handleTyping(project, editor, file);
29 private static Result handleTyping(Project project, Editor editor, PsiFile file) {
30 if (!StudyUtils.isStudyProject(project)) {
31 return Result.CONTINUE;
33 TaskFile taskFile = StudyUtils.getTaskFile(project, file.getVirtualFile());
34 if (taskFile == null || !taskFile.getTask().hasSubtasks()) {
35 return Result.CONTINUE;
37 int offset = editor.getCaretModel().getOffset();
38 boolean insidePlaceholder = taskFile.getAnswerPlaceholder(offset) != null;
39 if (!insidePlaceholder) {
40 HintManager.getInstance().showInformationHint(editor, "Text outside of placeholders is not editable in this task");
42 return insidePlaceholder ? Result.CONTINUE : Result.STOP;