Search in sources :

Example 86 with EditorEx

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

the class CfmlMatcherTest method doTest.

private void doTest() throws Throwable {
    final int pairOffset = configureByTestFile(getTestName(false));
    int offset = myFixture.getEditor().getCaretModel().getOffset();
    EditorHighlighter editorHighlighter = ((EditorEx) myFixture.getEditor()).getHighlighter();
    HighlighterIterator iterator = editorHighlighter.createIterator(offset);
    boolean forward = offset < pairOffset;
    boolean matched = BraceMatchingUtil.matchBrace(myFixture.getEditor().getDocument().getCharsSequence(), myFixture.getFile().getFileType(), iterator, forward);
    assertTrue(matched);
    assertEquals(pairOffset, iterator.getStart());
}
Also used : EditorEx(com.intellij.openapi.editor.ex.EditorEx) HighlighterIterator(com.intellij.openapi.editor.highlighter.HighlighterIterator) EditorHighlighter(com.intellij.openapi.editor.highlighter.EditorHighlighter)

Example 87 with EditorEx

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

the class DiffPreviewPanel method getChange.

@Nullable
private SimpleThreesideDiffChange getChange(ThreeSide side, EditorMouseEvent e) {
    EditorEx editor = myViewer.getEditor(side);
    LogicalPosition logicalPosition = editor.xyToLogicalPosition(e.getMouseEvent().getPoint());
    int offset = editor.logicalPositionToOffset(logicalPosition);
    int line = editor.getDocument().getLineNumber(offset);
    return getChange(side, line);
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition) EditorEx(com.intellij.openapi.editor.ex.EditorEx) Nullable(org.jetbrains.annotations.Nullable)

Example 88 with EditorEx

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

the class MethodSignatureComponent method createEditor.

@Override
protected EditorEx createEditor() {
    EditorEx editor = super.createEditor();
    final String fileName = getFileName();
    if (fileName != null) {
        editor.setHighlighter(EditorHighlighterFactory.getInstance().createEditorHighlighter(getProject(), fileName));
    }
    editor.getSettings().setWhitespacesShown(false);
    editor.setHorizontalScrollbarVisible(true);
    editor.setVerticalScrollbarVisible(true);
    return editor;
}
Also used : EditorEx(com.intellij.openapi.editor.ex.EditorEx)

Example 89 with EditorEx

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

the class HintManagerImpl method getHintPosition.

/**
   * @return coordinates in layered pane coordinate system.
   */
public Point getHintPosition(@NotNull LightweightHint hint, @NotNull Editor editor, @PositionFlags short constraint) {
    LogicalPosition pos = editor.getCaretModel().getLogicalPosition();
    final DataContext dataContext = ((EditorEx) editor).getDataContext();
    final Rectangle dominantArea = PlatformDataKeys.DOMINANT_HINT_AREA_RECTANGLE.getData(dataContext);
    LOG.assertTrue(SwingUtilities.isEventDispatchThread());
    if (dominantArea != null) {
        return getHintPositionRelativeTo(hint, editor, constraint, dominantArea, pos);
    }
    JRootPane rootPane = editor.getComponent().getRootPane();
    if (rootPane != null) {
        JLayeredPane lp = rootPane.getLayeredPane();
        for (HintInfo info : getHintsStackArray()) {
            if (!info.hint.isSelectingHint())
                continue;
            IdeTooltip tooltip = info.hint.getCurrentIdeTooltip();
            if (tooltip != null) {
                Point p = tooltip.getShowingPoint().getPoint(lp);
                if (info.hint != hint) {
                    switch(constraint) {
                        case ABOVE:
                            if (tooltip.getPreferredPosition() == Balloon.Position.below) {
                                p.y -= tooltip.getPositionChangeY();
                            }
                            break;
                        case UNDER:
                        case RIGHT_UNDER:
                            if (tooltip.getPreferredPosition() == Balloon.Position.above) {
                                p.y += tooltip.getPositionChangeY();
                            }
                            break;
                        case RIGHT:
                            if (tooltip.getPreferredPosition() == Balloon.Position.atLeft) {
                                p.x += tooltip.getPositionChangeX();
                            }
                            break;
                        case LEFT:
                            if (tooltip.getPreferredPosition() == Balloon.Position.atRight) {
                                p.x -= tooltip.getPositionChangeX();
                            }
                            break;
                    }
                }
                return p;
            }
            Rectangle rectangle = info.hint.getBounds();
            JComponent c = info.hint.getComponent();
            rectangle = SwingUtilities.convertRectangle(c.getParent(), rectangle, lp);
            return getHintPositionRelativeTo(hint, editor, constraint, rectangle, pos);
        }
    }
    return getHintPosition(hint, editor, pos, constraint);
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition) EditorEx(com.intellij.openapi.editor.ex.EditorEx) RelativePoint(com.intellij.ui.awt.RelativePoint) IdeTooltip(com.intellij.ide.IdeTooltip)

Example 90 with EditorEx

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

the class DocumentFragmentTooltipRenderer method show.

@Override
public LightweightHint show(@NotNull final Editor editor, @NotNull Point p, boolean alignToRight, @NotNull TooltipGroup group, @NotNull HintHint intInfo) {
    LightweightHint hint;
    final JComponent editorComponent = editor.getComponent();
    TextRange range = myDocumentFragment.getTextRange();
    int startOffset = range.getStartOffset();
    int endOffset = range.getEndOffset();
    Document doc = myDocumentFragment.getDocument();
    int endLine = doc.getLineNumber(endOffset);
    int startLine = doc.getLineNumber(startOffset);
    JLayeredPane layeredPane = editorComponent.getRootPane().getLayeredPane();
    // There is a possible case that collapsed folding region is soft wrapped, hence, we need to anchor
    // not logical but visual line start.
    VisualPosition visual = editor.offsetToVisualPosition(startOffset);
    p = editor.visualPositionToXY(visual);
    p = SwingUtilities.convertPoint(((EditorEx) editor).getGutterComponentEx(), p, layeredPane);
    p.x -= 3;
    p.y += editor.getLineHeight();
    Point screenPoint = new Point(p);
    SwingUtilities.convertPointToScreen(screenPoint, layeredPane);
    int maxLineCount = (ScreenUtil.getScreenRectangle(screenPoint).height - screenPoint.y) / editor.getLineHeight();
    if (endLine - startLine > maxLineCount) {
        endOffset = doc.getLineEndOffset(Math.max(0, Math.min(startLine + maxLineCount, doc.getLineCount() - 1)));
    }
    if (endOffset < startOffset)
        return null;
    FoldingModelEx foldingModel = (FoldingModelEx) editor.getFoldingModel();
    foldingModel.setFoldingEnabled(false);
    TextRange textRange = new TextRange(startOffset, endOffset);
    hint = EditorFragmentComponent.showEditorFragmentHintAt(editor, textRange, p.y, false, false, true, true, true);
    foldingModel.setFoldingEnabled(true);
    return hint;
}
Also used : EditorEx(com.intellij.openapi.editor.ex.EditorEx) LightweightHint(com.intellij.ui.LightweightHint) TextRange(com.intellij.openapi.util.TextRange) FoldingModelEx(com.intellij.openapi.editor.ex.FoldingModelEx) HintHint(com.intellij.ui.HintHint) LightweightHint(com.intellij.ui.LightweightHint)

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