Search in sources :

Example 71 with LogicalPosition

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

the class BlockSelectionEditingTest method testBlockSelectionAndCollapsedFolding.

public void testBlockSelectionAndCollapsedFolding() throws IOException {
    String text = "class Test {\n" + "    private class Inner1 {\n" + "        int i;\n" + "    }\n" + "\n" + "    private class Inner2 {\n" + "        int i;\n" + "    }\n" + "}";
    init(text, TestFileType.JAVA);
    int foldStart1 = text.indexOf("Inner1");
    foldStart1 = text.indexOf('{', foldStart1);
    int foldEnd1 = text.indexOf('}', foldStart1) + 1;
    addCollapsedFoldRegion(foldStart1, foldEnd1, "...");
    int foldStart2 = text.indexOf('{', foldEnd1);
    int foldEnd2 = text.indexOf('}', foldStart2) + 1;
    addCollapsedFoldRegion(foldStart2, foldEnd2, "...");
    LogicalPosition blockStart = new LogicalPosition(1, 4);
    LogicalPosition blockEnd = new LogicalPosition(5, 5 + "private".length());
    getEditor().getSelectionModel().setBlockSelection(blockStart, blockEnd);
    assertTrue(getFoldRegion(foldStart1).isExpanded());
    assertFalse(getFoldRegion(foldStart2).isExpanded());
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition)

Example 72 with LogicalPosition

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

the class BlockSelectionEditingTest method testBlockRemovalAndCollapsedFoldRegionsBefore.

public void testBlockRemovalAndCollapsedFoldRegionsBefore() throws IOException {
    // Inspired by IDEA-69371
    String initialText = "fold line #1\n" + "fold line #2\n" + "initialText    line 1\n" + "initialText    line 2\n" + "initialText    line 3";
    init(initialText, TestFileType.TEXT);
    final int foldEndOffset = initialText.indexOf("initialText");
    addCollapsedFoldRegion(0, foldEndOffset, "...");
    int column = "initialText".length();
    final LogicalPosition blockStart = new LogicalPosition(3, column);
    final LogicalPosition blockEnd = new LogicalPosition(4, column);
    final SelectionModel selectionModel = myEditor.getSelectionModel();
    selectionModel.setBlockSelection(blockStart, blockEnd);
    delete();
    delete();
    String expectedText = "fold line #1\n" + "fold line #2\n" + "initialText    line 1\n" + "initialText  line 2\n" + "initialText  line 3";
    assertEquals(expectedText, myEditor.getDocument().getText());
    assertSelectionRanges(new int[][] { { 59, 59 }, { 79, 79 } });
    final FoldRegion foldRegion = getFoldRegion(0);
    assertNotNull(foldRegion);
    assertEquals(0, foldRegion.getStartOffset());
    assertEquals(foldEndOffset, foldRegion.getEndOffset());
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition) SelectionModel(com.intellij.openapi.editor.SelectionModel) FoldRegion(com.intellij.openapi.editor.FoldRegion)

Example 73 with LogicalPosition

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

the class SubstitutionShortInfoHandler method mouseMoved.

public void mouseMoved(EditorMouseEvent e) {
    LogicalPosition position = editor.xyToLogicalPosition(e.getMouseEvent().getPoint());
    handleInputFocusMovement(position);
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition)

Example 74 with LogicalPosition

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

the class SyncScrollSupport method getTargetOffsets.

@NotNull
private static int[] getTargetOffsets(@NotNull Editor[] editors, int[] startLines, int[] endLines, int preferredTopShift) {
    int count = editors.length;
    assert startLines.length == count;
    assert endLines.length == count;
    int[] topOffsets = new int[count];
    int[] bottomOffsets = new int[count];
    int[] rangeHeights = new int[count];
    int[] gapLines = new int[count];
    int[] editorHeights = new int[count];
    int[] maximumOffsets = new int[count];
    int[] topShifts = new int[count];
    for (int i = 0; i < count; i++) {
        topOffsets[i] = editors[i].logicalPositionToXY(new LogicalPosition(startLines[i], 0)).y;
        bottomOffsets[i] = editors[i].logicalPositionToXY(new LogicalPosition(endLines[i] + 1, 0)).y;
        rangeHeights[i] = bottomOffsets[i] - topOffsets[i];
        gapLines[i] = 2 * editors[i].getLineHeight();
        editorHeights[i] = editors[i].getScrollingModel().getVisibleArea().height;
        maximumOffsets[i] = ((EditorEx) editors[i]).getScrollPane().getVerticalScrollBar().getMaximum() - editorHeights[i];
        // 'shift' here - distance between editor's top and first line of range
        // make whole range visible. If possible, locate it at 'center' (1/3 of height) (or at 'preferredTopShift' if it was specified)
        // If can't show whole range - show as much as we can
        boolean canShow = 2 * gapLines[i] + rangeHeights[i] <= editorHeights[i];
        int shift = preferredTopShift != -1 ? preferredTopShift : editorHeights[i] / 3;
        topShifts[i] = canShow ? Math.min(editorHeights[i] - gapLines[i] - rangeHeights[i], shift) : gapLines[i];
    }
    int topShift = ArrayUtil.min(topShifts);
    // check if we're at the top of file
    topShift = Math.min(topShift, ArrayUtil.min(topOffsets));
    int[] offsets = new int[count];
    boolean haveEnoughSpace = true;
    for (int i = 0; i < count; i++) {
        offsets[i] = topOffsets[i] - topShift;
        haveEnoughSpace &= maximumOffsets[i] > offsets[i];
    }
    if (haveEnoughSpace)
        return offsets;
    // One of the ranges is at end of file - we can't scroll where we want to.
    topShift = 0;
    for (int i = 0; i < count; i++) {
        topShift = Math.max(topOffsets[i] - maximumOffsets[i], topShift);
    }
    for (int i = 0; i < count; i++) {
        // Try to show as much of range as we can (even if it breaks alignment)
        offsets[i] = topOffsets[i] - topShift + Math.max(topShift + rangeHeights[i] + gapLines[i] - editorHeights[i], 0);
        // always show top of the range
        offsets[i] = Math.min(offsets[i], topOffsets[i] - gapLines[i]);
    }
    return offsets;
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition) EditorEx(com.intellij.openapi.editor.ex.EditorEx) NotNull(org.jetbrains.annotations.NotNull)

Example 75 with LogicalPosition

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

the class DiffRequestProcessor method notifyMessage.

private void notifyMessage(@NotNull AnActionEvent e, boolean next) {
    Editor editor = e.getData(DiffDataKeys.CURRENT_EDITOR);
    // TODO: provide "change" word in chain UserData - for tests/etc
    String message = DiffUtil.createNotificationText(next ? "Press again to go to the next file" : "Press again to go to the previous file", "You can disable this feature in " + DiffUtil.getSettingsConfigurablePath());
    final LightweightHint hint = new LightweightHint(HintUtil.createInformationLabel(message));
    Point point = new Point(myContentPanel.getWidth() / 2, next ? myContentPanel.getHeight() - JBUI.scale(40) : JBUI.scale(40));
    if (editor == null) {
        final Component owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
        final HintHint hintHint = createNotifyHint(myContentPanel, point, next);
        hint.show(myContentPanel, point.x, point.y, owner instanceof JComponent ? (JComponent) owner : null, hintHint);
    } else {
        int x = SwingUtilities.convertPoint(myContentPanel, point, editor.getComponent()).x;
        JComponent header = editor.getHeaderComponent();
        int shift = editor.getScrollingModel().getVerticalScrollOffset() - (header != null ? header.getHeight() : 0);
        LogicalPosition position;
        LineRange changeRange = e.getData(DiffDataKeys.CURRENT_CHANGE_RANGE);
        if (changeRange == null) {
            position = new LogicalPosition(editor.getCaretModel().getLogicalPosition().line + (next ? 1 : 0), 0);
        } else {
            position = new LogicalPosition(next ? changeRange.end : changeRange.start, 0);
        }
        int y = editor.logicalPositionToXY(position).y - shift;
        Point editorPoint = new Point(x, y);
        final HintHint hintHint = createNotifyHint(editor.getComponent(), editorPoint, !next);
        HintManagerImpl.getInstanceImpl().showEditorHint(hint, editor, editorPoint, HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_SCROLLING, 0, false, hintHint);
    }
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition) HintHint(com.intellij.ui.HintHint) LightweightHint(com.intellij.ui.LightweightHint) Editor(com.intellij.openapi.editor.Editor) LineRange(com.intellij.diff.util.LineRange) LightweightHint(com.intellij.ui.LightweightHint) HintHint(com.intellij.ui.HintHint)

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