Search in sources :

Example 6 with EditorEx

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

the class StudyToolWindow method enterEditingMode.

public void enterEditingMode(VirtualFile taskFile, Project project) {
    final EditorFactory factory = EditorFactory.getInstance();
    Document document = FileDocumentManager.getInstance().getDocument(taskFile);
    if (document == null) {
        return;
    }
    WebBrowserManager.getInstance().setShowBrowserHover(false);
    final EditorEx createdEditor = (EditorEx) factory.createEditor(document, project, taskFile, false);
    Disposer.register(project, new Disposable() {

        public void dispose() {
            factory.releaseEditor(createdEditor);
        }
    });
    JComponent editorComponent = createdEditor.getComponent();
    editorComponent.setBorder(new EmptyBorder(10, 20, 0, 10));
    editorComponent.setBackground(EditorColorsManager.getInstance().getGlobalScheme().getDefaultBackground());
    EditorSettings editorSettings = createdEditor.getSettings();
    editorSettings.setLineMarkerAreaShown(false);
    editorSettings.setLineNumbersShown(false);
    editorSettings.setFoldingOutlineShown(false);
    mySplitPane.setFirstComponent(editorComponent);
    mySplitPane.repaint();
    StudyTaskManager.getInstance(project).setToolWindowMode(StudyToolWindowMode.EDITING);
}
Also used : Disposable(com.intellij.openapi.Disposable) EditorFactory(com.intellij.openapi.editor.EditorFactory) EditorSettings(com.intellij.openapi.editor.EditorSettings) EditorEx(com.intellij.openapi.editor.ex.EditorEx) Document(com.intellij.openapi.editor.Document) EmptyBorder(javax.swing.border.EmptyBorder)

Example 7 with EditorEx

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

the class ResourceBundleEditor method createEditor.

private EditorEx createEditor() {
    EditorFactory editorFactory = EditorFactory.getInstance();
    Document document = editorFactory.createDocument("");
    EditorEx editor = (EditorEx) editorFactory.createEditor(document);
    reinitSettings(editor);
    editor.putUserData(RESOURCE_BUNDLE_EDITOR_KEY, this);
    return editor;
}
Also used : EditorEx(com.intellij.openapi.editor.ex.EditorEx)

Example 8 with EditorEx

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

Example 9 with EditorEx

use of com.intellij.openapi.editor.ex.EditorEx 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;
}
Also used : EditorEx(com.intellij.openapi.editor.ex.EditorEx) GroovyFile(org.jetbrains.plugins.groovy.lang.psi.GroovyFile) HighlighterIterator(com.intellij.openapi.editor.highlighter.HighlighterIterator) EditorHighlighter(com.intellij.openapi.editor.highlighter.EditorHighlighter)

Example 10 with EditorEx

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

the class SvnPropertiesDiffViewer method setupHighlighting.

private void setupHighlighting(@NotNull DiffChange change, @NotNull Side side) {
    PropertyRecord record = change.getRecord();
    List<? extends LineFragment> fragments = change.getFragments();
    assert fragments != null;
    EditorEx editor = getEditor(side);
    DocumentEx document = editor.getDocument();
    int changeStartLine = change.getStartLine(side);
    for (LineFragment fragment : fragments) {
        List<DiffFragment> innerFragments = fragment.getInnerFragments();
        int startLine = side.getStartLine(fragment) + changeStartLine;
        int endLine = side.getEndLine(fragment) + changeStartLine;
        int start = document.getLineStartOffset(startLine);
        TextDiffType type = DiffUtil.getLineDiffType(fragment);
        DiffDrawUtil.createHighlighter(editor, startLine, endLine, type, innerFragments != null);
        // TODO: we can paint LineMarker here, but it looks ugly for small editors
        if (innerFragments != null) {
            for (DiffFragment innerFragment : innerFragments) {
                int innerStart = side.getStartOffset(innerFragment);
                int innerEnd = side.getEndOffset(innerFragment);
                TextDiffType innerType = DiffUtil.getDiffType(innerFragment);
                innerStart += start;
                innerEnd += start;
                DiffDrawUtil.createInlineHighlighter(editor, innerStart, innerEnd, innerType);
            }
        }
    }
}
Also used : DocumentEx(com.intellij.openapi.editor.ex.DocumentEx) LineFragment(com.intellij.diff.fragments.LineFragment) EditorEx(com.intellij.openapi.editor.ex.EditorEx) DiffFragment(com.intellij.diff.fragments.DiffFragment)

Aggregations

EditorEx (com.intellij.openapi.editor.ex.EditorEx)164 EditorHighlighter (com.intellij.openapi.editor.highlighter.EditorHighlighter)36 Editor (com.intellij.openapi.editor.Editor)35 HighlighterIterator (com.intellij.openapi.editor.highlighter.HighlighterIterator)33 Document (com.intellij.openapi.editor.Document)29 NotNull (org.jetbrains.annotations.NotNull)26 IElementType (com.intellij.psi.tree.IElementType)14 Nullable (org.jetbrains.annotations.Nullable)13 Project (com.intellij.openapi.project.Project)12 PsiFile (com.intellij.psi.PsiFile)12 EditorFactory (com.intellij.openapi.editor.EditorFactory)11 VirtualFile (com.intellij.openapi.vfs.VirtualFile)11 TextRange (com.intellij.openapi.util.TextRange)10 FileType (com.intellij.openapi.fileTypes.FileType)8 LogicalPosition (com.intellij.openapi.editor.LogicalPosition)7 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)7 BraceMatcher (com.intellij.codeInsight.highlighting.BraceMatcher)6 Language (com.intellij.lang.Language)6 CaretModel (com.intellij.openapi.editor.CaretModel)6 EditorGutterComponentEx (com.intellij.openapi.editor.ex.EditorGutterComponentEx)6