Search in sources :

Example 6 with EditorImpl

use of com.intellij.openapi.editor.impl.EditorImpl in project intellij-community by JetBrains.

the class DaemonRespondToChangesTest method testApplyErrorInTheMiddle.

public void testApplyErrorInTheMiddle() throws Throwable {
    String text = "class <caret>X { ";
    for (int i = 0; i < 100; i++) {
        text += "\n    {\n" + "//    String x = \"<zzzzzzzzzz/>\";\n" + "    }";
    }
    text += "\n}";
    configureByText(StdFileTypes.JAVA, text);
    ((EditorImpl) myEditor).getScrollPane().getViewport().setSize(1000, 1000);
    DaemonCodeAnalyzerSettings.getInstance().setImportHintEnabled(true);
    List<HighlightInfo> warns = highlightErrors();
    assertEmpty(warns);
    type("//");
    List<HighlightInfo> errors = highlightErrors();
    assertEquals(2, errors.size());
    backspace();
    backspace();
    errors = highlightErrors();
    assertEmpty(errors);
}
Also used : EditorImpl(com.intellij.openapi.editor.impl.EditorImpl) LightweightHint(com.intellij.ui.LightweightHint)

Example 7 with EditorImpl

use of com.intellij.openapi.editor.impl.EditorImpl in project intellij-community by JetBrains.

the class CodeInsightTestCase method createEditor.

protected Editor createEditor(@NotNull VirtualFile file) {
    final FileEditorManager instance = FileEditorManager.getInstance(myProject);
    if (file.getFileType().isBinary())
        return null;
    PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
    Editor editor = instance.openTextEditor(new OpenFileDescriptor(myProject, file, 0), false);
    ((EditorImpl) editor).setCaretActive();
    PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
    DaemonCodeAnalyzer.getInstance(getProject()).restart();
    return editor;
}
Also used : FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) EditorImpl(com.intellij.openapi.editor.impl.EditorImpl) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) TextEditor(com.intellij.openapi.fileEditor.TextEditor) Editor(com.intellij.openapi.editor.Editor)

Example 8 with EditorImpl

use of com.intellij.openapi.editor.impl.EditorImpl in project intellij-community by JetBrains.

the class EditorFragmentComponent method doInit.

private void doInit(Component anchorComponent, EditorEx editor, int startLine, int endLine, boolean showFolding, boolean showGutter) {
    Document doc = editor.getDocument();
    final int endOffset = endLine < doc.getLineCount() ? doc.getLineEndOffset(endLine) : doc.getTextLength();
    boolean newRendering = editor instanceof EditorImpl;
    int widthAdjustment = newRendering ? EditorUtil.getSpaceWidth(Font.PLAIN, editor) : 0;
    final int textImageWidth = Math.min(editor.getMaxWidthInRange(doc.getLineStartOffset(startLine), endOffset) + widthAdjustment, getWidthLimit(editor));
    FoldingModelEx foldingModel = editor.getFoldingModel();
    boolean isFoldingEnabled = foldingModel.isFoldingEnabled();
    if (!showFolding) {
        foldingModel.setFoldingEnabled(false);
    }
    Point p1 = editor.logicalPositionToXY(new LogicalPosition(startLine, 0));
    Point p2 = editor.logicalPositionToXY(new LogicalPosition(Math.max(endLine, startLine + 1), 0));
    int y1 = p1.y;
    int y2 = p2.y;
    final int textImageHeight = y2 - y1 == 0 ? editor.getLineHeight() : y2 - y1;
    LOG.assertTrue(textImageHeight > 0, "Height: " + textImageHeight + "; startLine:" + startLine + "; endLine:" + endLine + "; p1:" + p1 + "; p2:" + p2);
    int savedScrollOffset = newRendering ? 0 : editor.getScrollingModel().getHorizontalScrollOffset();
    if (savedScrollOffset > 0) {
        editor.getScrollingModel().scrollHorizontally(0);
    }
    final BufferedImage textImage = UIUtil.createImage(anchorComponent == null ? editor.getContentComponent() : anchorComponent, textImageWidth, textImageHeight, BufferedImage.TYPE_INT_RGB);
    Graphics textGraphics = textImage.getGraphics();
    EditorUIUtil.setupAntialiasing(textGraphics);
    final JComponent rowHeader;
    final BufferedImage markersImage;
    final int markersImageWidth;
    if (showGutter) {
        rowHeader = editor.getGutterComponentEx();
        markersImageWidth = Math.max(1, rowHeader.getWidth());
        markersImage = UIUtil.createImage(editor.getComponent(), markersImageWidth, textImageHeight, BufferedImage.TYPE_INT_RGB);
        Graphics markerGraphics = markersImage.getGraphics();
        EditorUIUtil.setupAntialiasing(markerGraphics);
        markerGraphics.translate(0, -y1);
        markerGraphics.setClip(0, y1, rowHeader.getWidth(), textImageHeight);
        markerGraphics.setColor(getBackgroundColor(editor));
        markerGraphics.fillRect(0, y1, rowHeader.getWidth(), textImageHeight);
        rowHeader.paint(markerGraphics);
    } else {
        markersImageWidth = 0;
        rowHeader = null;
        markersImage = null;
    }
    textGraphics.translate(0, -y1);
    textGraphics.setClip(0, y1, textImageWidth, textImageHeight);
    final boolean wasVisible = editor.setCaretVisible(false);
    editor.getContentComponent().paint(textGraphics);
    if (wasVisible) {
        editor.setCaretVisible(true);
    }
    if (!showFolding) {
        foldingModel.setFoldingEnabled(isFoldingEnabled);
    }
    if (savedScrollOffset > 0) {
        editor.getScrollingModel().scrollHorizontally(savedScrollOffset);
    }
    JComponent component = new JComponent() {

        @Override
        public Dimension getPreferredSize() {
            return new Dimension(textImageWidth + markersImageWidth, textImageHeight);
        }

        @Override
        protected void paintComponent(Graphics graphics) {
            if (markersImage != null) {
                UIUtil.drawImage(graphics, markersImage, 0, 0, null);
                UIUtil.drawImage(graphics, textImage, rowHeader.getWidth(), 0, null);
            } else {
                UIUtil.drawImage(graphics, textImage, 0, 0, null);
            }
        }
    };
    setLayout(new BorderLayout());
    add(component);
    final Color borderColor = editor.getColorsScheme().getColor(EditorColors.SELECTED_TEARLINE_COLOR);
    Border outsideBorder = JBUI.Borders.customLine(borderColor, LINE_BORDER_THICKNESS);
    Border insideBorder = JBUI.Borders.empty(EMPTY_BORDER_THICKNESS, EMPTY_BORDER_THICKNESS);
    setBorder(BorderFactory.createCompoundBorder(outsideBorder, insideBorder));
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition) EditorImpl(com.intellij.openapi.editor.impl.EditorImpl) Document(com.intellij.openapi.editor.Document) FoldingModelEx(com.intellij.openapi.editor.ex.FoldingModelEx) HintHint(com.intellij.ui.HintHint) LightweightHint(com.intellij.ui.LightweightHint) BufferedImage(java.awt.image.BufferedImage) Border(javax.swing.border.Border)

Example 9 with EditorImpl

use of com.intellij.openapi.editor.impl.EditorImpl in project intellij-community by JetBrains.

the class EventLogConsole method installNotificationsFont.

private void installNotificationsFont(@NotNull final EditorEx editor) {
    final DelegateColorScheme globalScheme = new DelegateColorScheme(EditorColorsManager.getInstance().getGlobalScheme()) {

        @Override
        public String getEditorFontName() {
            return getConsoleFontName();
        }

        @Override
        public int getEditorFontSize() {
            return getConsoleFontSize();
        }

        @Override
        public String getConsoleFontName() {
            return NotificationsUtil.getFontName();
        }

        @Override
        public int getConsoleFontSize() {
            Pair<String, Integer> data = NotificationsUtil.getFontData();
            return data == null ? super.getConsoleFontSize() : data.second;
        }

        @Override
        public void setEditorFontName(String fontName) {
        }

        @Override
        public void setConsoleFontName(String fontName) {
        }

        @Override
        public void setEditorFontSize(int fontSize) {
        }

        @Override
        public void setConsoleFontSize(int fontSize) {
        }
    };
    ApplicationManager.getApplication().getMessageBus().connect(myProjectModel).subscribe(EditorColorsManager.TOPIC, new EditorColorsListener() {

        @Override
        public void globalSchemeChange(EditorColorsScheme scheme) {
            globalScheme.setDelegate(EditorColorsManager.getInstance().getGlobalScheme());
            editor.reinitSettings();
        }
    });
    editor.setColorsScheme(ConsoleViewUtil.updateConsoleColorScheme(editor.createBoundColorSchemeDelegate(globalScheme)));
    if (editor instanceof EditorImpl) {
        ((EditorImpl) editor).setUseEditorAntialiasing(false);
    }
}
Also used : EditorColorsListener(com.intellij.openapi.editor.colors.EditorColorsListener) EditorImpl(com.intellij.openapi.editor.impl.EditorImpl) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) DelegateColorScheme(com.intellij.openapi.editor.colors.impl.DelegateColorScheme)

Example 10 with EditorImpl

use of com.intellij.openapi.editor.impl.EditorImpl in project intellij-community by JetBrains.

the class SoftWrapApplianceOnDocumentModificationTest method testLeadingTabWithShiftedWidth.

public void testLeadingTabWithShiftedWidth() throws IOException {
    // Inspired by IDEA-76353. The point is that we need to consider cached information about tab symbols width during logical
    // position to offset mapping
    String text = "\t test";
    init(15, text);
    ((EditorImpl) myEditor).setPrefixTextAndAttributes(" ", new TextAttributes());
    myEditor.getCaretModel().moveToOffset(text.length());
}
Also used : EditorImpl(com.intellij.openapi.editor.impl.EditorImpl) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes)

Aggregations

EditorImpl (com.intellij.openapi.editor.impl.EditorImpl)34 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)8 Editor (com.intellij.openapi.editor.Editor)7 LightweightHint (com.intellij.ui.LightweightHint)6 Document (com.intellij.openapi.editor.Document)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 EditorMouseFixture (com.intellij.testFramework.fixtures.EditorMouseFixture)3 NotNull (org.jetbrains.annotations.NotNull)3 IntentionHintComponent (com.intellij.codeInsight.intention.impl.IntentionHintComponent)2 Result (com.intellij.openapi.application.Result)2 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)2 SoftWrap (com.intellij.openapi.editor.SoftWrap)2 EditorEx (com.intellij.openapi.editor.ex.EditorEx)2 FoldingModelEx (com.intellij.openapi.editor.ex.FoldingModelEx)2 SoftWrapModelImpl (com.intellij.openapi.editor.impl.SoftWrapModelImpl)2 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)2 TextEditor (com.intellij.openapi.fileEditor.TextEditor)2 Project (com.intellij.openapi.project.Project)2 HintHint (com.intellij.ui.HintHint)2 EditorHintListener (com.intellij.codeInsight.hint.EditorHintListener)1