mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
do not allow to edit text outside of placeholders in tasks with subtasks
This commit is contained in:
committed by
liana.bakradze
parent
e03cf4cead
commit
6ed0347b98
@@ -107,6 +107,7 @@
|
||||
<applicationService serviceImplementation="com.jetbrains.edu.learning.statistics.EduUsagesCollector"/>
|
||||
<applicationService serviceImplementation="com.jetbrains.edu.learning.stepic.StepicUpdateSettings"/>
|
||||
<editorTabTitleProvider implementation="com.jetbrains.edu.learning.StudyTabTitleProvider"/>
|
||||
<typedHandler implementation="com.jetbrains.edu.learning.StudyTypeHandlerDelegate" order="first, before completionAutoPopup"/>
|
||||
</extensions>
|
||||
|
||||
<extensions defaultExtensionNs="Edu">
|
||||
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
package com.jetbrains.edu.learning;
|
||||
|
||||
import com.intellij.codeInsight.editorActions.TypedHandlerDelegate;
|
||||
import com.intellij.codeInsight.hint.HintManager;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.fileTypes.FileType;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.jetbrains.edu.learning.courseFormat.TaskFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class StudyTypeHandlerDelegate extends TypedHandlerDelegate {
|
||||
|
||||
@Override
|
||||
public Result checkAutoPopup(char charTyped, Project project, Editor editor, PsiFile file) {
|
||||
return handleTyping(project, editor, file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result beforeCharTyped(char c,
|
||||
Project project,
|
||||
Editor editor,
|
||||
PsiFile file,
|
||||
FileType fileType) {
|
||||
return handleTyping(project, editor, file);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Result handleTyping(Project project, Editor editor, PsiFile file) {
|
||||
if (!StudyUtils.isStudyProject(project)) {
|
||||
return Result.CONTINUE;
|
||||
}
|
||||
TaskFile taskFile = StudyUtils.getTaskFile(project, file.getVirtualFile());
|
||||
if (taskFile == null || !taskFile.getTask().hasSubtasks()) {
|
||||
return Result.CONTINUE;
|
||||
}
|
||||
int offset = editor.getCaretModel().getOffset();
|
||||
boolean insidePlaceholder = taskFile.getAnswerPlaceholder(offset) != null;
|
||||
if (!insidePlaceholder) {
|
||||
HintManager.getInstance().showInformationHint(editor, "Text outside of placeholders is not editable in this task");
|
||||
}
|
||||
return insidePlaceholder ? Result.CONTINUE : Result.STOP;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user