use of com.intellij.openapi.editor.highlighter.EditorHighlighter in project intellij-community by JetBrains.
the class TypedHandler method indentBrace.
private static void indentBrace(@NotNull final Project project, @NotNull final Editor editor, final char braceChar) {
final int offset = editor.getCaretModel().getOffset() - 1;
final 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);
final FileType fileType = file.getFileType();
BraceMatcher braceMatcher = BraceMatchingUtil.getBraceMatcher(fileType, iterator);
boolean rBraceToken = braceMatcher.isRBraceToken(iterator, chars, fileType);
final boolean isBrace = braceMatcher.isLBraceToken(iterator, chars, fileType) || rBraceToken;
int lBraceOffset = -1;
if (CodeInsightSettings.getInstance().REFORMAT_BLOCK_ON_RBRACE && rBraceToken && braceMatcher.isStructuralBrace(iterator, chars, fileType) && offset > 0) {
lBraceOffset = BraceMatchingUtil.findLeftLParen(highlighter.createIterator(offset - 1), braceMatcher.getOppositeBraceTokenType(iterator.getTokenType()), editor.getDocument().getCharsSequence(), fileType);
}
if (element.getNode() != null && isBrace) {
final int finalLBraceOffset = lBraceOffset;
ApplicationManager.getApplication().runWriteAction(() -> {
try {
int newOffset;
if (finalLBraceOffset != -1) {
RangeMarker marker = document.createRangeMarker(offset, offset + 1);
CodeStyleManager.getInstance(project).reformatRange(file, finalLBraceOffset, offset, true);
newOffset = marker.getStartOffset();
marker.dispose();
} else {
newOffset = CodeStyleManager.getInstance(project).adjustLineIndent(file, offset);
}
editor.getCaretModel().moveToOffset(newOffset + 1);
editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
editor.getSelectionModel().removeSelection();
} catch (IncorrectOperationException e) {
LOG.error(e);
}
});
}
}
}
use of com.intellij.openapi.editor.highlighter.EditorHighlighter in project intellij-community by JetBrains.
the class DiffUtil method initEmptyEditorHighlighter.
@NotNull
public static EditorHighlighter initEmptyEditorHighlighter(@NotNull CharSequence text) {
EditorHighlighter highlighter = createEmptyEditorHighlighter();
highlighter.setText(text);
return highlighter;
}
use of com.intellij.openapi.editor.highlighter.EditorHighlighter in project intellij-community by JetBrains.
the class TestEditorManagerImpl method openTextEditor.
@Override
public Editor openTextEditor(@NotNull OpenFileDescriptor descriptor, boolean focusEditor) {
final VirtualFile file = descriptor.getFile();
Editor editor = myVirtualFile2Editor.get(file);
if (editor == null) {
PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file);
LOG.assertTrue(psiFile != null, file);
Document document = PsiDocumentManager.getInstance(myProject).getDocument(psiFile);
LOG.assertTrue(document != null, psiFile);
editor = EditorFactory.getInstance().createEditor(document, myProject);
final EditorHighlighter highlighter = HighlighterFactory.createHighlighter(myProject, file);
((EditorEx) editor).setHighlighter(highlighter);
((EditorEx) editor).setFile(file);
myVirtualFile2Editor.put(file, editor);
}
if (descriptor.getOffset() >= 0) {
editor.getCaretModel().moveToOffset(descriptor.getOffset());
} else if (descriptor.getLine() >= 0 && descriptor.getColumn() >= 0) {
editor.getCaretModel().moveToLogicalPosition(new LogicalPosition(descriptor.getLine(), descriptor.getColumn()));
}
editor.getSelectionModel().removeSelection();
myActiveFile = file;
return editor;
}
use of com.intellij.openapi.editor.highlighter.EditorHighlighter in project intellij-community by JetBrains.
the class DetailViewImpl method createEditor.
@NotNull
protected Editor createEditor(@Nullable Project project, Document document, VirtualFile file) {
EditorEx editor = (EditorEx) EditorFactory.getInstance().createViewer(document, project);
final EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
EditorHighlighter highlighter = EditorHighlighterFactory.getInstance().createEditorHighlighter(file, scheme, project);
editor.setFile(file);
editor.setHighlighter(highlighter);
EditorSettings settings = editor.getSettings();
settings.setAnimatedScrolling(false);
settings.setRefrainFromScrolling(false);
settings.setLineNumbersShown(true);
settings.setFoldingOutlineShown(false);
if (settings instanceof SettingsImpl) {
((SettingsImpl) settings).setSoftWrapAppliancePlace(SoftWrapAppliancePlaces.PREVIEW);
}
editor.getFoldingModel().setFoldingEnabled(false);
return editor;
}
use of com.intellij.openapi.editor.highlighter.EditorHighlighter in project intellij-community by JetBrains.
the class JavaBraceMatcherTest method testBinaryStatement.
public void testBinaryStatement() {
myFixture.configureByText("a.java", "import java.util.ArrayList;" + "class A {" + " int i = 3 <caret>< 4 ? 5 > 6 : 1 : 1 : 1;" + "}");
final Editor editor = myFixture.getEditor();
final EditorHighlighter editorHighlighter = ((EditorEx) editor).getHighlighter();
final HighlighterIterator iterator = editorHighlighter.createIterator(editor.getCaretModel().getOffset());
boolean matched = BraceMatchingUtil.matchBrace(editor.getDocument().getCharsSequence(), myFixture.getFile().getFileType(), iterator, true);
assertFalse(matched);
}
Aggregations