Search in sources :

Example 16 with LogicalPosition

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

the class AbstractToggleUseSoftWrapsAction method toggleSoftWraps.

public static void toggleSoftWraps(@NotNull Editor editor, @Nullable SoftWrapAppliancePlaces places, boolean state) {
    Point point = editor.getScrollingModel().getVisibleArea().getLocation();
    LogicalPosition anchorPosition = editor.xyToLogicalPosition(point);
    int intraLineShift = point.y - editor.logicalPositionToXY(anchorPosition).y;
    if (places != null) {
        EditorSettingsExternalizable.getInstance().setUseSoftWraps(state, places);
        EditorFactory.getInstance().refreshAllEditors();
    }
    if (editor.getSettings().isUseSoftWraps() != state) {
        editor.getSettings().setUseSoftWraps(state);
    }
    editor.getScrollingModel().disableAnimation();
    editor.getScrollingModel().scrollVertically(editor.logicalPositionToXY(anchorPosition).y + intraLineShift);
    editor.getScrollingModel().enableAnimation();
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition)

Example 17 with LogicalPosition

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

the class DividerPolygon method getVisibleInterval.

static Interval getVisibleInterval(Editor editor) {
    int offset = editor.getScrollingModel().getVerticalScrollOffset();
    LogicalPosition logicalPosition = editor.xyToLogicalPosition(new Point(0, offset));
    int line = logicalPosition.line;
    return new Interval(line, editor.getComponent().getHeight() / editor.getLineHeight() + 1);
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition)

Example 18 with LogicalPosition

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

the class DartStatementMover method checkAvailable.

@Override
public boolean checkAvailable(@NotNull Editor editor, @NotNull PsiFile file, @NotNull MoveInfo info, boolean down) {
    if (!(file instanceof DartFile))
        return false;
    if (!super.checkAvailable(editor, file, info, down))
        return false;
    LineRange range = expandLineRangeToCoverPsiElements(info.toMove, editor, file);
    if (range == null)
        return false;
    info.toMove = range;
    final int startOffset = editor.logicalPositionToOffset(new LogicalPosition(range.startLine, 0));
    final int endOffset = editor.logicalPositionToOffset(new LogicalPosition(range.endLine, 0));
    PsiElement[] statements = DartRefactoringUtil.findListExpressionInRange(file, startOffset, endOffset);
    if (statements.length == 1) {
        // Disallow component mover
        info.toMove2 = null;
        // Require trailing comma
        return true;
    }
    if (statements.length == 0) {
        statements = DartRefactoringUtil.findStatementsInRange(file, startOffset, endOffset);
    }
    if (statements.length == 0)
        return false;
    range.firstElement = statements[0];
    range.lastElement = statements[statements.length - 1];
    info.indentTarget = true;
    if (!checkMovingInsideOutside(file, editor, info, down)) {
        info.toMove2 = null;
    }
    return true;
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition) LineRange(com.intellij.codeInsight.editorActions.moveUpDown.LineRange) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement)

Example 19 with LogicalPosition

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

the class BraceHighlightingHandler method showScopeHint.

private void showScopeHint(final int lbraceStart, final int lbraceEnd) {
    LogicalPosition bracePosition = myEditor.offsetToLogicalPosition(lbraceStart);
    Point braceLocation = myEditor.logicalPositionToXY(bracePosition);
    final int y = braceLocation.y;
    myAlarm.addRequest(() -> {
        if (myProject.isDisposed())
            return;
        PsiDocumentManager.getInstance(myProject).performLaterWhenAllCommitted(() -> {
            if (!myEditor.getComponent().isShowing())
                return;
            Rectangle viewRect = myEditor.getScrollingModel().getVisibleArea();
            if (y < viewRect.y) {
                int start = lbraceStart;
                if (!(myPsiFile instanceof PsiPlainTextFile) && myPsiFile.isValid()) {
                    start = BraceMatchingUtil.getBraceMatcher(getFileTypeByOffset(lbraceStart), PsiUtilCore.getLanguageAtOffset(myPsiFile, lbraceStart)).getCodeConstructStart(myPsiFile, lbraceStart);
                }
                TextRange range = new TextRange(start, lbraceEnd);
                int line1 = myDocument.getLineNumber(range.getStartOffset());
                int line2 = myDocument.getLineNumber(range.getEndOffset());
                line1 = Math.max(line1, line2 - 5);
                range = new TextRange(myDocument.getLineStartOffset(line1), range.getEndOffset());
                LightweightHint hint = EditorFragmentComponent.showEditorFragmentHint(myEditor, range, true, true);
                myEditor.putUserData(HINT_IN_EDITOR_KEY, hint);
            }
        });
    }, 300, ModalityState.stateForComponent(myEditor.getComponent()));
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition) LightweightHint(com.intellij.ui.LightweightHint) TextRange(com.intellij.openapi.util.TextRange) LightweightHint(com.intellij.ui.LightweightHint)

Example 20 with LogicalPosition

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

the class LookupUi method calculatePosition.

// in layered pane coordinate system.
Rectangle calculatePosition() {
    final JComponent lookupComponent = myLookup.getComponent();
    Dimension dim = lookupComponent.getPreferredSize();
    int lookupStart = myLookup.getLookupStart();
    Editor editor = myLookup.getTopLevelEditor();
    if (lookupStart < 0 || lookupStart > editor.getDocument().getTextLength()) {
        LOG.error(lookupStart + "; offset=" + editor.getCaretModel().getOffset() + "; element=" + myLookup.getPsiElement());
    }
    LogicalPosition pos = editor.offsetToLogicalPosition(lookupStart);
    Point location = editor.logicalPositionToXY(pos);
    location.y += editor.getLineHeight();
    location.x -= myLookup.myCellRenderer.getTextIndent();
    // extra check for other borders
    final Window window = UIUtil.getWindow(lookupComponent);
    if (window != null) {
        final Point point = SwingUtilities.convertPoint(lookupComponent, 0, 0, window);
        location.x -= point.x;
    }
    SwingUtilities.convertPointToScreen(location, editor.getContentComponent());
    final Rectangle screenRectangle = ScreenUtil.getScreenRectangle(location);
    if (!isPositionedAboveCaret()) {
        int shiftLow = screenRectangle.height - (location.y + dim.height);
        myPositionedAbove = shiftLow < 0 && shiftLow < location.y - dim.height && location.y >= dim.height;
    }
    if (isPositionedAboveCaret()) {
        location.y -= dim.height + editor.getLineHeight();
        if (pos.line == 0) {
            location.y += 1;
        //otherwise the lookup won't intersect with the editor and every editor's resize (e.g. after typing in console) will close the lookup
        }
    }
    if (!screenRectangle.contains(location)) {
        location = ScreenUtil.findNearestPointOnBorder(screenRectangle, location);
    }
    final JRootPane rootPane = editor.getComponent().getRootPane();
    if (rootPane == null) {
        LOG.error("editor.disposed=" + editor.isDisposed() + "; lookup.disposed=" + myLookup.isLookupDisposed() + "; editorShowing=" + editor.getContentComponent().isShowing());
    }
    Rectangle candidate = new Rectangle(location, dim);
    ScreenUtil.cropRectangleToFitTheScreen(candidate);
    SwingUtilities.convertPointFromScreen(location, rootPane.getLayeredPane());
    myMaximumHeight = candidate.height;
    return new Rectangle(location.x, location.y, dim.width, candidate.height);
}
Also used : EditorWindow(com.intellij.injected.editor.EditorWindow) LogicalPosition(com.intellij.openapi.editor.LogicalPosition) Editor(com.intellij.openapi.editor.Editor)

Aggregations

LogicalPosition (com.intellij.openapi.editor.LogicalPosition)106 Document (com.intellij.openapi.editor.Document)16 PsiElement (com.intellij.psi.PsiElement)14 Editor (com.intellij.openapi.editor.Editor)12 TextRange (com.intellij.openapi.util.TextRange)11 VirtualFile (com.intellij.openapi.vfs.VirtualFile)10 EditorEx (com.intellij.openapi.editor.ex.EditorEx)7 CaretModel (com.intellij.openapi.editor.CaretModel)6 NotNull (org.jetbrains.annotations.NotNull)6 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 EditorWindow (com.intellij.injected.editor.EditorWindow)3