use of com.intellij.openapi.editor.highlighter.EditorHighlighter in project kotlin by JetBrains.
the class KotlinTypedHandler method indentBrace.
/**
* Copied from
* @see com.intellij.codeInsight.editorActions.TypedHandler#indentBrace(Project, Editor, char)
*/
private static void indentBrace(@NotNull final Project project, @NotNull final Editor editor, char braceChar) {
final int offset = editor.getCaretModel().getOffset() - 1;
Document document = editor.getDocument();
CharSequence chars = document.getCharsSequence();
if (offset < 0 || chars.charAt(offset) != braceChar)
return;
int spaceStart = CharArrayUtil.shiftBackward(chars, offset - 1, " \t");
if (spaceStart < 0 || chars.charAt(spaceStart) == '\n' || chars.charAt(spaceStart) == '\r') {
PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
documentManager.commitDocument(document);
final PsiFile file = documentManager.getPsiFile(document);
if (file == null || !file.isWritable())
return;
PsiElement element = file.findElementAt(offset);
if (element == null)
return;
EditorHighlighter highlighter = ((EditorEx) editor).getHighlighter();
HighlighterIterator iterator = highlighter.createIterator(offset);
FileType fileType = file.getFileType();
BraceMatcher braceMatcher = BraceMatchingUtil.getBraceMatcher(fileType, iterator);
boolean isBrace = braceMatcher.isLBraceToken(iterator, chars, fileType) || braceMatcher.isRBraceToken(iterator, chars, fileType);
if (element.getNode() != null && isBrace) {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
int newOffset = CodeStyleManager.getInstance(project).adjustLineIndent(file, offset);
editor.getCaretModel().moveToOffset(newOffset + 1);
editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
editor.getSelectionModel().removeSelection();
}
});
}
}
}
use of com.intellij.openapi.editor.highlighter.EditorHighlighter in project intellij-community by JetBrains.
the class HtmlSelectioner method select.
@Override
public List<TextRange> select(PsiElement e, @NotNull CharSequence editorText, int cursorOffset, @NotNull Editor editor) {
List<TextRange> result;
if (!(e instanceof XmlToken) || XmlTokenSelectioner.shouldSelectToken((XmlToken) e) || ((XmlToken) e).getTokenType() == XmlTokenType.XML_DATA_CHARACTERS) {
result = super.select(e, editorText, cursorOffset, editor);
} else {
result = ContainerUtil.newArrayList();
}
final PsiElement parent = e.getParent();
if (parent instanceof XmlComment) {
result.addAll(expandToWholeLine(editorText, parent.getTextRange(), true));
}
PsiFile psiFile = e.getContainingFile();
addAttributeSelection(result, editor, cursorOffset, editorText, e);
final FileViewProvider fileViewProvider = psiFile.getViewProvider();
for (Language lang : fileViewProvider.getLanguages()) {
final PsiFile langFile = fileViewProvider.getPsi(lang);
if (langFile != psiFile)
addAttributeSelection(result, editor, cursorOffset, editorText, fileViewProvider.findElementAt(cursorOffset, lang));
}
EditorHighlighter highlighter = HighlighterFactory.createHighlighter(e.getProject(), psiFile.getVirtualFile());
highlighter.setText(editorText);
addTagSelection2(e, result);
return result;
}
use of com.intellij.openapi.editor.highlighter.EditorHighlighter in project intellij-community by JetBrains.
the class PyUtil method rehighlightOpenEditors.
/**
* Force re-highlighting in all open editors that belong to specified project.
*/
public static void rehighlightOpenEditors(@NotNull final Project project) {
ApplicationManager.getApplication().runWriteAction(() -> {
for (Editor editor : EditorFactory.getInstance().getAllEditors()) {
if (editor instanceof EditorEx && editor.getProject() == project) {
final VirtualFile vFile = ((EditorEx) editor).getVirtualFile();
if (vFile != null) {
final EditorHighlighter highlighter = EditorHighlighterFactory.getInstance().createEditorHighlighter(project, vFile);
((EditorEx) editor).setHighlighter(highlighter);
}
}
}
});
}
use of com.intellij.openapi.editor.highlighter.EditorHighlighter in project intellij-community by JetBrains.
the class XmlHighlightingTest method testXHtmlEditorHighlighting.
public void testXHtmlEditorHighlighting() throws Exception {
// 10
// 0123456789012
String text = "<html></html>";
EditorHighlighter xhtmlHighlighter = HighlighterFactory.createHighlighter(StdFileTypes.XHTML, EditorColorsManager.getInstance().getGlobalScheme(), myProject);
xhtmlHighlighter.setText(text);
HighlighterIterator iterator = xhtmlHighlighter.createIterator(1);
assertSame("Xml tag name", iterator.getTokenType(), XmlTokenType.XML_TAG_NAME);
iterator = xhtmlHighlighter.createIterator(8);
assertSame("Xml tag name at end of tag", iterator.getTokenType(), XmlTokenType.XML_TAG_NAME);
}
use of com.intellij.openapi.editor.highlighter.EditorHighlighter in project intellij-community by JetBrains.
the class GStringTypedActionHandler method charTyped.
@Override
public Result charTyped(char c, Project project, @NotNull Editor editor, @NotNull PsiFile file) {
if (c != '{' || project == null || !HandlerUtils.canBeInvoked(editor, project)) {
return Result.CONTINUE;
}
if (!(file instanceof GroovyFile))
return Result.CONTINUE;
int caret = editor.getCaretModel().getOffset();
final EditorHighlighter highlighter = ((EditorEx) editor).getHighlighter();
if (caret < 1)
return Result.CONTINUE;
HighlighterIterator iterator = highlighter.createIterator(caret - 1);
if (iterator.getTokenType() != GroovyTokenTypes.mLCURLY)
return Result.CONTINUE;
iterator.retreat();
if (iterator.atEnd() || iterator.getTokenType() != GroovyTokenTypes.mDOLLAR)
return Result.CONTINUE;
iterator.advance();
if (iterator.atEnd())
return Result.CONTINUE;
iterator.advance();
if (iterator.getTokenType() != GroovyTokenTypes.mGSTRING_BEGIN)
return Result.CONTINUE;
editor.getDocument().insertString(caret, "}");
return Result.STOP;
}
Aggregations