Search in sources :

Example 61 with LogicalPosition

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

the class FlexNavigationTest method doTestLibCss.

// we cannot use <caret> method, because lib css file is read-only
private void doTestLibCss(int line, int column) throws Exception {
    myAfterCommitRunnable = () -> FlexTestUtils.addLibrary(myModule, "Lib", getTestDataPath() + BASE_PATH, "LibWithCssFile.swc", "LibWithCssFile_src.zip", null);
    configureByFile(BASE_PATH + "CssEmptyFile.css");
    final VirtualFile cssFile = getFile("LibWithCssFile.swc!/defaults.css");
    configureByExistingFile(cssFile);
    myEditor.getCaretModel().moveToLogicalPosition(new LogicalPosition(line, column));
    final VirtualFile classFile = getFile("LibWithCssFile_src.zip!/p1/p2/MyClass.as");
    doTest(classFile, null, null);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LogicalPosition(com.intellij.openapi.editor.LogicalPosition)

Example 62 with LogicalPosition

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

the class ActionUtil method getCodePointer.

static CodePointer getCodePointer(Editor editor) {
    CodePointer codePointer;
    int selectionStart = editor.getSelectionModel().getSelectionStart();
    int selectionEnd = editor.getSelectionModel().getSelectionEnd();
    if (selectionStart != selectionEnd) {
        LogicalPosition start = editor.offsetToLogicalPosition(selectionStart);
        LogicalPosition end = editor.offsetToLogicalPosition(selectionEnd);
        codePointer = new CodePointer(start.line, start.column, end.line, end.column);
    } else {
        LogicalPosition pos = editor.getCaretModel().getLogicalPosition();
        codePointer = new CodePointer(pos.line, pos.column);
    }
    return codePointer;
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition) CodePointer(jetbrains.communicator.core.vfs.CodePointer)

Example 63 with LogicalPosition

use of com.intellij.openapi.editor.LogicalPosition 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 64 with LogicalPosition

use of com.intellij.openapi.editor.LogicalPosition 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 65 with LogicalPosition

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

the class HintManagerImpl method showEditorHint.

/**
   * In this method the point to show hint depends on current caret position.
   * So, first of all, editor will be scrolled to make the caret position visible.
   */
public void showEditorHint(final LightweightHint hint, final Editor editor, @PositionFlags final short constraint, @HideFlags final int flags, final int timeout, final boolean reviveOnEditorChange) {
    editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
    editor.getScrollingModel().runActionOnScrollingFinished(() -> {
        LogicalPosition pos = editor.getCaretModel().getLogicalPosition();
        Point p = getHintPosition(hint, editor, pos, constraint);
        showEditorHint(hint, editor, p, flags, timeout, reviveOnEditorChange, createHintHint(editor, p, hint, constraint));
    });
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition) RelativePoint(com.intellij.ui.awt.RelativePoint)

Aggregations

LogicalPosition (com.intellij.openapi.editor.LogicalPosition)97 Document (com.intellij.openapi.editor.Document)12 PsiElement (com.intellij.psi.PsiElement)12 Editor (com.intellij.openapi.editor.Editor)11 TextRange (com.intellij.openapi.util.TextRange)10 VirtualFile (com.intellij.openapi.vfs.VirtualFile)9 EditorEx (com.intellij.openapi.editor.ex.EditorEx)7 NotNull (org.jetbrains.annotations.NotNull)6 CaretModel (com.intellij.openapi.editor.CaretModel)5 RelativePoint (com.intellij.ui.awt.RelativePoint)5 JSFile (com.intellij.lang.javascript.psi.JSFile)4 EditorColorsManager (com.intellij.openapi.editor.colors.EditorColorsManager)4 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)4 Project (com.intellij.openapi.project.Project)4 PsiFile (com.intellij.psi.PsiFile)4 PsiReference (com.intellij.psi.PsiReference)4 PsiMultiReference (com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference)4 Mark (com.maddyhome.idea.vim.common.Mark)4 HighlightManager (com.intellij.codeInsight.highlighting.HighlightManager)3 EditorHighlighter (com.intellij.openapi.editor.highlighter.EditorHighlighter)3