Search in sources :

Example 76 with EditorEx

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

Example 77 with EditorEx

use of com.intellij.openapi.editor.ex.EditorEx in project intellij-code-outline by sitano.

the class CodeOutlineImageEx method renderRestOfLineToImg.

/**
     * Renders the characters at the given document offset to the code outline
     * image until the first newline character is reached or until the right
     * edge of the image is reached and no more characters can be rendered.
     *
     * @param startOff the offset into the document at which to start rendering
     * @return how many characters were rendered, not including the newline
     */
@Override
protected int renderRestOfLineToImg(int startOff) {
    final CharSequence chars = document.getCharsSequence();
    final int endOff = document.getTextLength();
    if (startOff >= endOff)
        return 0;
    final LogicalPosition startPos = editor.offsetToLogicalPosition(startOff);
    final int line = startPos.line;
    final EditorEx ex = (EditorEx) editor;
    final EditorHighlighter hl = ex.getHighlighter();
    final HighlighterIterator hi = hl.createIterator(startOff);
    int col = startPos.column;
    int painted = 0;
    for (int i = startOff; i < endOff; i++) {
        final char ch = chars.charAt(i);
        while (!hi.atEnd() && i > hi.getEnd()) {
            hi.advance();
        }
        if (ch == '\n')
            break;
        if (col >= visibleImgWidth)
            break;
        drawChar(ch, col, line, getCharColor(editor, hi));
        painted++;
        col++;
    }
    return painted;
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition) EditorEx(com.intellij.openapi.editor.ex.EditorEx) HighlighterIterator(com.intellij.openapi.editor.highlighter.HighlighterIterator) EditorHighlighter(com.intellij.openapi.editor.highlighter.EditorHighlighter)

Example 78 with EditorEx

use of com.intellij.openapi.editor.ex.EditorEx in project intellij-plugins by JetBrains.

the class MarkdownCssSettingsForm method createEditor.

@NotNull
private static Editor createEditor() {
    EditorFactory editorFactory = EditorFactory.getInstance();
    Document editorDocument = editorFactory.createDocument("");
    EditorEx editor = (EditorEx) editorFactory.createEditor(editorDocument);
    fillEditorSettings(editor.getSettings());
    setHighlighting(editor);
    return editor;
}
Also used : EditorFactory(com.intellij.openapi.editor.EditorFactory) EditorEx(com.intellij.openapi.editor.ex.EditorEx) Document(com.intellij.openapi.editor.Document) NotNull(org.jetbrains.annotations.NotNull)

Example 79 with EditorEx

use of com.intellij.openapi.editor.ex.EditorEx in project intellij-plugins by JetBrains.

the class ManifestEditor method createEditor.

@Override
protected EditorEx createEditor() {
    EditorEx editor = super.createEditor();
    editor.setVerticalScrollbarVisible(true);
    editor.setHorizontalScrollbarVisible(true);
    return editor;
}
Also used : EditorEx(com.intellij.openapi.editor.ex.EditorEx)

Example 80 with EditorEx

use of com.intellij.openapi.editor.ex.EditorEx in project intellij-community by JetBrains.

the class CheckRegExpForm method createUIComponents.

private void createUIComponents() {
    myProject = myRegexpFile.getProject();
    Document document = PsiDocumentManager.getInstance(myProject).getDocument(myRegexpFile);
    final Language language = myRegexpFile.getLanguage();
    final LanguageFileType fileType;
    if (language instanceof RegExpLanguage) {
        fileType = RegExpLanguage.INSTANCE.getAssociatedFileType();
    } else {
        // for correct syntax highlighting
        fileType = new RegExpFileType(language);
    }
    myRegExp = new EditorTextField(document, myProject, fileType);
    final String sampleText = PropertiesComponent.getInstance(myProject).getValue(LAST_EDITED_REGEXP, "Sample Text");
    mySampleText = new EditorTextField(sampleText, myProject, PlainTextFileType.INSTANCE) {

        @Override
        protected void updateBorder(@NotNull EditorEx editor) {
            setupBorder(editor);
        }
    };
    mySampleText.setOneLineMode(false);
    int preferredWidth = Math.max(JBUI.scale(250), myRegExp.getPreferredSize().width);
    myRegExp.setPreferredWidth(preferredWidth);
    mySampleText.setPreferredWidth(preferredWidth);
    myRootPanel = new JPanel(new BorderLayout()) {

        Disposable disposable;

        Alarm updater;

        @Override
        public void addNotify() {
            super.addNotify();
            disposable = Disposer.newDisposable();
            IdeFocusManager.getGlobalInstance().requestFocus(mySampleText, true);
            new AnAction() {

                @Override
                public void actionPerformed(AnActionEvent e) {
                    IdeFocusManager.findInstance().requestFocus(myRegExp.getFocusTarget(), true);
                }
            }.registerCustomShortcutSet(CustomShortcutSet.fromString("shift TAB"), mySampleText);
            updater = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, disposable);
            DocumentAdapter documentListener = new DocumentAdapter() {

                @Override
                public void documentChanged(DocumentEvent e) {
                    update();
                }
            };
            myRegExp.addDocumentListener(documentListener);
            mySampleText.addDocumentListener(documentListener);
            update();
            mySampleText.selectAll();
        }

        public void update() {
            final TransactionId transactionId = TransactionGuard.getInstance().getContextTransaction();
            updater.cancelAllRequests();
            if (!updater.isDisposed()) {
                updater.addRequest(() -> {
                    final RegExpMatchResult result = isMatchingText(myRegexpFile, mySampleText.getText());
                    TransactionGuard.getInstance().submitTransaction(myProject, transactionId, () -> setBalloonState(result));
                }, 200);
            }
        }

        @Override
        public void removeNotify() {
            super.removeNotify();
            Disposer.dispose(disposable);
            PropertiesComponent.getInstance(myProject).setValue(LAST_EDITED_REGEXP, mySampleText.getText());
        }
    };
    myRootPanel.setBorder(JBUI.Borders.empty(UIUtil.DEFAULT_VGAP, UIUtil.DEFAULT_HGAP));
}
Also used : Disposable(com.intellij.openapi.Disposable) EditorEx(com.intellij.openapi.editor.ex.EditorEx) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) Document(com.intellij.openapi.editor.Document) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) TransactionId(com.intellij.openapi.application.TransactionId) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) Language(com.intellij.lang.Language) EditorTextField(com.intellij.ui.EditorTextField) Alarm(com.intellij.util.Alarm)

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