use of com.perl5.lang.tt2.TemplateToolkitFileViewProvider in project Perl5-IDEA by Camelcade.
the class TemplateToolkitTypedHandler method processChar.
protected Result processChar(char c, Project project, Editor editor, PsiFile file, FileType fileType) {
FileViewProvider viewProvider = file.getViewProvider();
if (!(viewProvider instanceof TemplateToolkitFileViewProvider)) {
return null;
}
TemplateToolkitSettings settings = TemplateToolkitSettings.getInstance(project);
String openTag = settings.START_TAG;
if (StringUtil.isEmpty(openTag) || c != openTag.charAt(openTag.length() - 1)) {
return null;
}
int offset = editor.getCaretModel().getOffset();
if (offset == 0) {
return null;
}
PsiElement element = viewProvider.findElementAt(offset - 1, TemplateToolkitLanguage.INSTANCE);
if (element == null) {
return null;
}
IElementType tokenType = element.getNode().getElementType();
if (tokenType != TT2_HTML) {
return null;
}
String openTagPrefix = openTag.substring(0, openTag.length() - 1);
if (openTagPrefix.length() == 0) {
return null;
}
int startOffset = offset - openTagPrefix.length();
if (startOffset < 0) {
return null;
}
if (StringUtil.equals(file.getText().subSequence(startOffset, offset), openTagPrefix)) {
EditorModificationUtil.insertStringAtCaret(editor, c + " " + settings.END_TAG, false, true, 2);
return Result.STOP;
}
return null;
}
Aggregations