Search in sources :

Example 81 with EditorEx

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++;
        }
    }
}
Also used : EditorEx(com.intellij.openapi.editor.ex.EditorEx) HighlighterIterator(com.intellij.openapi.editor.highlighter.HighlighterIterator) EditorHighlighter(com.intellij.openapi.editor.highlighter.EditorHighlighter)

Example 82 with EditorEx

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;
}
Also used : EditorEx(com.intellij.openapi.editor.ex.EditorEx) Editor(com.intellij.openapi.editor.Editor) com.intellij.openapi.fileEditor(com.intellij.openapi.fileEditor)

Example 83 with EditorEx

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);
    }
}
Also used : EditorEx(com.intellij.openapi.editor.ex.EditorEx) Editor(com.intellij.openapi.editor.Editor)

Example 84 with EditorEx

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;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) EditorEx(com.intellij.openapi.editor.ex.EditorEx) HighlighterIterator(com.intellij.openapi.editor.highlighter.HighlighterIterator) EditorHighlighter(com.intellij.openapi.editor.highlighter.EditorHighlighter)

Example 85 with EditorEx

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;
}
Also used : PsiErrorElement(com.intellij.psi.PsiErrorElement) EditorEx(com.intellij.openapi.editor.ex.EditorEx) CfmlTag(com.intellij.coldFusion.model.psi.CfmlTag) Document(com.intellij.openapi.editor.Document) HighlighterIterator(com.intellij.openapi.editor.highlighter.HighlighterIterator) PsiElement(com.intellij.psi.PsiElement) PsiDocumentManager(com.intellij.psi.PsiDocumentManager)

Aggregations

EditorEx (com.intellij.openapi.editor.ex.EditorEx)153 Editor (com.intellij.openapi.editor.Editor)32 EditorHighlighter (com.intellij.openapi.editor.highlighter.EditorHighlighter)32 HighlighterIterator (com.intellij.openapi.editor.highlighter.HighlighterIterator)28 NotNull (org.jetbrains.annotations.NotNull)23 Document (com.intellij.openapi.editor.Document)22 EditorFactory (com.intellij.openapi.editor.EditorFactory)11 Nullable (org.jetbrains.annotations.Nullable)11 TextRange (com.intellij.openapi.util.TextRange)10 Project (com.intellij.openapi.project.Project)9 IElementType (com.intellij.psi.tree.IElementType)9 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 LogicalPosition (com.intellij.openapi.editor.LogicalPosition)7 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)7 PsiFile (com.intellij.psi.PsiFile)7 BraceMatcher (com.intellij.codeInsight.highlighting.BraceMatcher)6 EditorGutterComponentEx (com.intellij.openapi.editor.ex.EditorGutterComponentEx)6 RangeHighlighter (com.intellij.openapi.editor.markup.RangeHighlighter)6 FileType (com.intellij.openapi.fileTypes.FileType)6 Language (com.intellij.lang.Language)5