Search in sources :

Example 31 with EditorEx

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

the class SimpleDiffChange method createOperation.

//
// Helpers
//
@NotNull
private MyGutterOperation createOperation(@NotNull Side side) {
    int offset = side.getStartOffset(myFragment);
    EditorEx editor = myViewer.getEditor(side);
    RangeHighlighter highlighter = editor.getMarkupModel().addRangeHighlighter(offset, offset, HighlighterLayer.ADDITIONAL_SYNTAX, null, HighlighterTargetArea.LINES_IN_RANGE);
    return new MyGutterOperation(side, highlighter);
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) EditorEx(com.intellij.openapi.editor.ex.EditorEx) NotNull(org.jetbrains.annotations.NotNull)

Example 32 with EditorEx

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

the class DocumentMarkupModelTest method testInfoTestAttributes.

public void testInfoTestAttributes() throws Exception {
    LanguageExtensionPoint<Annotator> extension = new LanguageExtensionPoint<>();
    extension.language = "TEXT";
    extension.implementationClass = TestAnnotator.class.getName();
    PlatformTestUtil.registerExtension(ExtensionPointName.create(LanguageAnnotators.EP_NAME), extension, myFixture.getTestRootDisposable());
    myFixture.configureByText(PlainTextFileType.INSTANCE, "foo");
    EditorColorsScheme scheme = new EditorColorsSchemeImpl(new DefaultColorsScheme()) {

        {
            initFonts();
        }
    };
    scheme.setAttributes(HighlighterColors.TEXT, new TextAttributes(Color.black, Color.white, null, null, Font.PLAIN));
    ((EditorEx) myFixture.getEditor()).setColorsScheme(scheme);
    myFixture.doHighlighting();
    MarkupModel model = DocumentMarkupModel.forDocument(myFixture.getEditor().getDocument(), getProject(), false);
    RangeHighlighter[] highlighters = model.getAllHighlighters();
    assertThat(highlighters).hasSize(1);
    TextAttributes attributes = highlighters[0].getTextAttributes();
    assertThat(attributes).isNotNull();
    assertThat(attributes.getBackgroundColor()).isNull();
    assertThat(attributes.getForegroundColor()).isNull();
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) EditorEx(com.intellij.openapi.editor.ex.EditorEx) Annotator(com.intellij.lang.annotation.Annotator) EditorColorsSchemeImpl(com.intellij.openapi.editor.colors.impl.EditorColorsSchemeImpl) DefaultColorsScheme(com.intellij.openapi.editor.colors.impl.DefaultColorsScheme) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) LanguageExtensionPoint(com.intellij.lang.LanguageExtensionPoint) MarkupModel(com.intellij.openapi.editor.markup.MarkupModel)

Example 33 with EditorEx

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

the class ConsoleViewUtil method setupConsoleEditor.

@NotNull
public static EditorEx setupConsoleEditor(Project project, final boolean foldingOutlineShown, final boolean lineMarkerAreaShown) {
    EditorFactory editorFactory = EditorFactory.getInstance();
    Document document = ((EditorFactoryImpl) editorFactory).createDocument(true);
    UndoUtil.disableUndoFor(document);
    EditorEx editor = (EditorEx) editorFactory.createViewer(document, project);
    setupConsoleEditor(editor, foldingOutlineShown, lineMarkerAreaShown);
    return editor;
}
Also used : EditorEx(com.intellij.openapi.editor.ex.EditorEx) EditorFactoryImpl(com.intellij.openapi.editor.impl.EditorFactoryImpl) NotNull(org.jetbrains.annotations.NotNull)

Example 34 with EditorEx

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

the class EventLogToolWindowFactory method createContent.

static void createContent(Project project, ToolWindow toolWindow, EventLogConsole console, String title) {
    // update default Event Log tab title
    ContentManager contentManager = toolWindow.getContentManager();
    Content generalContent = contentManager.getContent(0);
    if (generalContent != null && contentManager.getContentCount() == 1) {
        generalContent.setDisplayName("General");
    }
    final Editor editor = console.getConsoleEditor();
    JPanel editorPanel = new JPanel(new AbstractLayoutManager() {

        private int getOffset() {
            return JBUI.scale(4);
        }

        @Override
        public Dimension preferredLayoutSize(Container parent) {
            Dimension size = parent.getComponent(0).getPreferredSize();
            return new Dimension(size.width + getOffset(), size.height);
        }

        @Override
        public void layoutContainer(Container parent) {
            int offset = getOffset();
            parent.getComponent(0).setBounds(offset, 0, parent.getWidth() - offset, parent.getHeight());
        }
    }) {

        @Override
        public Color getBackground() {
            return ((EditorEx) editor).getBackgroundColor();
        }
    };
    editorPanel.add(editor.getComponent());
    SimpleToolWindowPanel panel = new SimpleToolWindowPanel(false, true) {

        @Override
        public Object getData(@NonNls String dataId) {
            return PlatformDataKeys.HELP_ID.is(dataId) ? EventLog.HELP_ID : super.getData(dataId);
        }
    };
    panel.setContent(editorPanel);
    panel.addAncestorListener(new LogShownTracker(project));
    ActionToolbar toolbar = createToolbar(project, editor, console);
    toolbar.setTargetComponent(editor.getContentComponent());
    panel.setToolbar(toolbar.getComponent());
    Content content = ContentFactory.SERVICE.getInstance().createContent(panel, title, false);
    contentManager.addContent(content);
    contentManager.setSelectedContent(content);
}
Also used : NonNls(org.jetbrains.annotations.NonNls) EditorEx(com.intellij.openapi.editor.ex.EditorEx) ContentManager(com.intellij.ui.content.ContentManager) AbstractLayoutManager(com.intellij.util.ui.AbstractLayoutManager) SimpleToolWindowPanel(com.intellij.openapi.ui.SimpleToolWindowPanel) Content(com.intellij.ui.content.Content) Editor(com.intellij.openapi.editor.Editor)

Example 35 with EditorEx

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

the class ToggleColumnModeAction method setSelected.

@Override
public void setSelected(AnActionEvent e, boolean state) {
    final EditorEx editor = getEditor(e);
    final SelectionModel selectionModel = editor.getSelectionModel();
    final CaretModel caretModel = editor.getCaretModel();
    if (state) {
        caretModel.removeSecondaryCarets();
        boolean hasSelection = selectionModel.hasSelection();
        int selStart = selectionModel.getSelectionStart();
        int selEnd = selectionModel.getSelectionEnd();
        LogicalPosition blockStart, blockEnd;
        if (caretModel.supportsMultipleCarets()) {
            LogicalPosition logicalSelStart = editor.offsetToLogicalPosition(selStart);
            LogicalPosition logicalSelEnd = editor.offsetToLogicalPosition(selEnd);
            int caretOffset = caretModel.getOffset();
            blockStart = selStart == caretOffset ? logicalSelEnd : logicalSelStart;
            blockEnd = selStart == caretOffset ? logicalSelStart : logicalSelEnd;
        } else {
            blockStart = selStart == caretModel.getOffset() ? caretModel.getLogicalPosition() : editor.offsetToLogicalPosition(selStart);
            blockEnd = selEnd == caretModel.getOffset() ? caretModel.getLogicalPosition() : editor.offsetToLogicalPosition(selEnd);
        }
        editor.setColumnMode(true);
        if (hasSelection) {
            selectionModel.setBlockSelection(blockStart, blockEnd);
        } else {
            selectionModel.removeSelection();
        }
    } else {
        boolean hasSelection = false;
        int selStart = 0;
        int selEnd = 0;
        if (caretModel.supportsMultipleCarets()) {
            hasSelection = true;
            List<Caret> allCarets = caretModel.getAllCarets();
            Caret fromCaret = allCarets.get(0);
            Caret toCaret = allCarets.get(allCarets.size() - 1);
            if (fromCaret == caretModel.getPrimaryCaret()) {
                Caret tmp = fromCaret;
                fromCaret = toCaret;
                toCaret = tmp;
            }
            selStart = fromCaret.getLeadSelectionOffset();
            selEnd = toCaret.getSelectionStart() == toCaret.getLeadSelectionOffset() ? toCaret.getSelectionEnd() : toCaret.getSelectionStart();
        }
        editor.setColumnMode(false);
        caretModel.removeSecondaryCarets();
        if (hasSelection) {
            selectionModel.setSelection(selStart, selEnd);
        } else {
            selectionModel.removeSelection();
        }
    }
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition) EditorEx(com.intellij.openapi.editor.ex.EditorEx) CaretModel(com.intellij.openapi.editor.CaretModel) SelectionModel(com.intellij.openapi.editor.SelectionModel) Caret(com.intellij.openapi.editor.Caret)

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