use of com.intellij.openapi.editor.ex.EditorEx in project intellij-code-outline by sitano.
the class CodeOutlineImageEx method renderToImg.
/**
* Renders the given characters to the code outline image starting at the
* given position.
*
* @param chars a character array
* @param offset the offset into the given array to start rendering
* @param len the number of characters to render
* @param pos the position at which to start rendering
*/
@Override
protected void renderToImg(CharSequence chars, int offset, int len, LogicalPosition pos) {
if (img == null)
return;
final EditorEx ex = (EditorEx) editor;
final EditorHighlighter hl = ex.getHighlighter();
final HighlighterIterator hi = hl.createIterator(offset);
int line = pos.line, col = pos.column;
// Render characters
for (int i = offset; i < len; i++) {
final char ch = chars.charAt(i);
while (!hi.atEnd() && i > hi.getEnd()) {
hi.advance();
}
if (ch == '\n') {
line++;
if (getScaledLine(line, scale) >= visibleImgHeight)
break;
col = 0;
} else {
if (col >= visibleImgWidth)
continue;
// Whitespaces are skipped inside drawChar
drawChar(ch, col, line, getCharColor(editor, hi));
col++;
}
}
}
use of com.intellij.openapi.editor.ex.EditorEx in project intellij-code-outline by sitano.
the class CodeOutlineToolWindow method openPanel.
/**
* Opens a code outline panel for the given file editor and file. The panel
* is not shown, only created.
*
* @param fileEditor a file editor
* @param file a file
*/
private synchronized CodeOutlinePanel openPanel(FileEditor fileEditor, VirtualFile file) {
final Editor editor = ((TextEditor) fileEditor).getEditor();
final CodeOutlinePanel panel = editor instanceof EditorEx ? new CodeOutlinePanel(plugin, project, (EditorEx) editor) : new CodeOutlinePanel(plugin, project, editor);
editor2panel.put(fileEditor, panel);
file2panel.put(file, panel);
return panel;
}
use of com.intellij.openapi.editor.ex.EditorEx in project android by JetBrains.
the class CreateClassAction method showOverridesDialog.
private static void showOverridesDialog(@NotNull AnActionEvent event) {
Editor editor = FileEditorManager.getInstance(event.getProject()).getSelectedTextEditor();
if (editor instanceof EditorEx) {
EditorEx editorEx = (EditorEx) editor;
AnActionEvent newEvent = new AnActionEvent(event.getInputEvent(), editorEx.getDataContext(), ActionPlaces.UNKNOWN, event.getPresentation(), event.getActionManager(), 0);
ActionManager.getInstance().getAction("OverrideMethods").actionPerformed(newEvent);
}
}
use of com.intellij.openapi.editor.ex.EditorEx in project intellij-plugins by JetBrains.
the class CfmlEnterHandler method isBetweenCfmlTags.
private static boolean isBetweenCfmlTags(PsiFile file, Editor editor, int offset) {
if (offset == 0)
return false;
CharSequence chars = editor.getDocument().getCharsSequence();
if (chars.charAt(offset - 1) != '>')
return false;
EditorHighlighter highlighter = ((EditorEx) editor).getHighlighter();
HighlighterIterator iterator = highlighter.createIterator(offset - 1);
if (iterator.getTokenType() != CfmlTokenTypes.R_ANGLEBRACKET)
return false;
iterator.retreat();
int retrieveCount = 1;
while (!iterator.atEnd()) {
final IElementType tokenType = iterator.getTokenType();
if (tokenType == CfmlTokenTypes.LSLASH_ANGLEBRACKET)
return false;
if (tokenType == CfmlTokenTypes.OPENER)
break;
++retrieveCount;
iterator.retreat();
}
for (int i = 0; i < retrieveCount; ++i) iterator.advance();
iterator.advance();
return !iterator.atEnd() && iterator.getTokenType() == CfmlTokenTypes.LSLASH_ANGLEBRACKET;
}
use of com.intellij.openapi.editor.ex.EditorEx in project intellij-plugins by JetBrains.
the class CfmlTypedHandler method insertCloseTagIfNeeded.
public static boolean insertCloseTagIfNeeded(Editor editor, PsiFile file, Project project) {
final Document document = editor.getDocument();
final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
int offset = editor.getCaretModel().getOffset();
documentManager.commitDocument(document);
char charAtOffset = DocumentUtils.getCharAt(document, offset);
if (charAtOffset != '>') {
EditorModificationUtil.insertStringAtCaret(editor, ">", true, 0);
}
EditorModificationUtil.moveCaretRelatively(editor, 1);
++offset;
if (DocumentUtils.getCharAt(document, offset - 2) == '/') {
return false;
}
HighlighterIterator iterator = ((EditorEx) editor).getHighlighter().createIterator(offset - 2);
while (!iterator.atEnd() && !iterator.getTokenType().equals(CfmlTokenTypes.CF_TAG_NAME)) {
if (CfmlUtil.isControlToken(iterator.getTokenType())) {
return false;
}
iterator.retreat();
}
if (!iterator.atEnd()) {
iterator.retreat();
if (!iterator.atEnd() && iterator.getTokenType().equals(CfmlTokenTypes.LSLASH_ANGLEBRACKET)) {
return false;
}
iterator.advance();
}
if (iterator.atEnd()) {
return false;
}
String tagName = document.getCharsSequence().subSequence(iterator.getStart(), iterator.getEnd()).toString();
if (CfmlUtil.isSingleCfmlTag(tagName, project) || CfmlUtil.isUserDefined(tagName)) {
return false;
}
PsiElement tagElement = file.findElementAt(iterator.getStart());
while (tagElement != null && !(tagElement instanceof CfmlTag)) {
tagElement = tagElement.getParent();
}
if (tagElement == null) {
return false;
}
boolean doInsertion = false;
if (tagElement.getLastChild() instanceof PsiErrorElement) {
doInsertion = true;
} else {
iterator = ((EditorEx) editor).getHighlighter().createIterator(0);
while (!iterator.atEnd() && iterator.getStart() < offset) {
if (iterator.getTokenType() == CfmlTokenTypes.CF_TAG_NAME) {
String currentTagName = document.getCharsSequence().subSequence(iterator.getStart(), iterator.getEnd()).toString();
if (tagName.equals(currentTagName)) {
PsiElement currentTagElement = file.findElementAt(iterator.getStart());
currentTagElement = PsiTreeUtil.getParentOfType(currentTagElement, CfmlTag.class);
if (currentTagElement.getLastChild() instanceof PsiErrorElement) {
doInsertion = true;
break;
}
}
}
iterator.advance();
}
}
// tag name in lowercase
String tagNameFromPsi = ((CfmlTag) tagElement).getTagName();
if (doInsertion && CfmlUtil.isEndTagRequired(tagNameFromPsi, project)) {
if (!Comparing.equal(tagNameFromPsi, tagName, false)) {
// use tagName because it has proper case
tagName = tagNameFromPsi;
}
EditorModificationUtil.insertStringAtCaret(editor, "</" + tagName + ">", true, 0);
return true;
}
return false;
}
Aggregations