Search in sources :

Example 11 with LogicalPosition

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

the class DebuggerUIUtil method calcPopupLocation.

@Deprecated
public static RelativePoint calcPopupLocation(@NotNull Editor editor, final int line) {
    Point p = editor.logicalPositionToXY(new LogicalPosition(line + 1, 0));
    final Rectangle visibleArea = editor.getScrollingModel().getVisibleArea();
    if (!visibleArea.contains(p)) {
        p = new Point((visibleArea.x + visibleArea.width) / 2, (visibleArea.y + visibleArea.height) / 2);
    }
    return new RelativePoint(editor.getContentComponent(), p);
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 12 with LogicalPosition

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

the class VisibleHighlightingPassFactory method calculateVisibleRange.

@NotNull
public static ProperTextRange calculateVisibleRange(@NotNull Editor editor) {
    Rectangle rect = editor.getScrollingModel().getVisibleArea();
    LogicalPosition startPosition = editor.xyToLogicalPosition(new Point(rect.x, rect.y));
    int visibleStart = editor.logicalPositionToOffset(startPosition);
    LogicalPosition endPosition = editor.xyToLogicalPosition(new Point(rect.x + rect.width, rect.y + rect.height));
    int visibleEnd = editor.logicalPositionToOffset(new LogicalPosition(endPosition.line + 1, 0));
    return new ProperTextRange(visibleStart, Math.max(visibleEnd, visibleStart));
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition) ProperTextRange(com.intellij.openapi.util.ProperTextRange) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with LogicalPosition

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

the class MergeSearchHelper method findChangeAt.

public static Change findChangeAt(EditorMouseEvent e, MergePanel2 mergePanel, int index) {
    if (mergePanel.getMergeList() == null)
        return null;
    Editor editor = e.getEditor();
    LOG.assertTrue(editor == mergePanel.getEditor(index));
    LogicalPosition logicalPosition = editor.xyToLogicalPosition(e.getMouseEvent().getPoint());
    int offset = editor.logicalPositionToOffset(logicalPosition);
    return forMergeList(mergePanel.getMergeList(), index).findChangeAt(offset);
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition) Editor(com.intellij.openapi.editor.Editor)

Example 14 with LogicalPosition

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

the class ScrollToTheEndToolbarAction method setSelected.

@Override
public void setSelected(AnActionEvent e, boolean state) {
    if (state) {
        EditorUtil.scrollToTheEnd(myEditor);
    } else {
        int lastLine = Math.max(0, myEditor.getDocument().getLineCount() - 1);
        LogicalPosition currentPosition = myEditor.getCaretModel().getLogicalPosition();
        LogicalPosition position = new LogicalPosition(Math.max(0, Math.min(currentPosition.line, lastLine - 1)), currentPosition.column);
        myEditor.getCaretModel().moveToLogicalPosition(position);
    }
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition)

Example 15 with LogicalPosition

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

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