Search in sources :

Example 1 with EditingSides

use of com.intellij.openapi.diff.impl.EditingSides in project intellij-community by JetBrains.

the class SyncScrollSupport method install.

public void install(EditingSides[] sideContainers) {
    Disposer.dispose(this);
    Editor[] editors = new Editor[sideContainers.length + 1];
    editors[0] = sideContainers[0].getEditor(FragmentSide.SIDE1);
    for (int i = 0; i < sideContainers.length; i++) {
        EditingSides sideContainer = sideContainers[i];
        LOG.assertTrue(sideContainer.getEditor(FragmentSide.SIDE1) == editors[i]);
        editors[i + 1] = sideContainer.getEditor(FragmentSide.SIDE2);
    }
    if (editors.length == 3)
        install3(editors, sideContainers);
    else if (editors.length == 2)
        install2(editors, sideContainers);
    else
        LOG.error(String.valueOf(editors.length));
}
Also used : EditingSides(com.intellij.openapi.diff.impl.EditingSides) Editor(com.intellij.openapi.editor.Editor)

Example 2 with EditingSides

use of com.intellij.openapi.diff.impl.EditingSides in project intellij-community by JetBrains.

the class SyncScrollSupport method syncHorizontalScroll.

private static void syncHorizontalScroll(@NotNull ScrollingContext context, @NotNull Rectangle newRectangle, @NotNull Rectangle oldRectangle) {
    int newScrollOffset = newRectangle.x;
    if (newScrollOffset == oldRectangle.x)
        return;
    EditingSides sidesContainer = context.getSidesContainer();
    FragmentSide masterSide = context.getMasterSide();
    Editor slaveEditor = sidesContainer.getEditor(masterSide.otherSide());
    if (slaveEditor == null)
        return;
    doScrollHorizontally(slaveEditor.getScrollingModel(), newScrollOffset);
}
Also used : EditingSides(com.intellij.openapi.diff.impl.EditingSides) FragmentSide(com.intellij.openapi.diff.impl.highlighting.FragmentSide) Editor(com.intellij.openapi.editor.Editor)

Example 3 with EditingSides

use of com.intellij.openapi.diff.impl.EditingSides in project intellij-community by JetBrains.

the class SyncScrollSupport method syncVerticalScroll.

private static void syncVerticalScroll(@NotNull ScrollingContext context, @NotNull Rectangle newRectangle, @NotNull Rectangle oldRectangle) {
    if (newRectangle.y == oldRectangle.y)
        return;
    EditingSides sidesContainer = context.getSidesContainer();
    FragmentSide masterSide = context.getMasterSide();
    FragmentSide masterDiffSide = context.getMasterDiffSide();
    Editor master = sidesContainer.getEditor(masterSide);
    Editor slave = sidesContainer.getEditor(masterSide.otherSide());
    if (master == null || slave == null)
        return;
    if (master.isDisposed() || slave.isDisposed())
        return;
    int masterVerticalScrollOffset = master.getScrollingModel().getVerticalScrollOffset();
    int slaveVerticalScrollOffset = slave.getScrollingModel().getVerticalScrollOffset();
    Rectangle viewRect = master.getScrollingModel().getVisibleArea();
    int middleY = viewRect.height / 3;
    if (master.getDocument().getTextLength() == 0)
        return;
    LogicalPosition masterPos = master.xyToLogicalPosition(new Point(viewRect.x, masterVerticalScrollOffset + middleY));
    int masterCenterLine = masterPos.line;
    int scrollToLine = sidesContainer.getLineBlocks().transform(masterDiffSide, masterCenterLine);
    int offset;
    if (scrollToLine < 0) {
        offset = slaveVerticalScrollOffset + newRectangle.y - oldRectangle.y;
    } else {
        int correction = (masterVerticalScrollOffset + middleY) % master.getLineHeight();
        Point point = slave.logicalPositionToXY(new LogicalPosition(scrollToLine, masterPos.column));
        offset = point.y - middleY + correction;
    }
    int deltaHeaderOffset = getHeaderOffset(slave) - getHeaderOffset(master);
    doScrollVertically(slave.getScrollingModel(), offset + deltaHeaderOffset);
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition) EditingSides(com.intellij.openapi.diff.impl.EditingSides) FragmentSide(com.intellij.openapi.diff.impl.highlighting.FragmentSide) Editor(com.intellij.openapi.editor.Editor)

Aggregations

EditingSides (com.intellij.openapi.diff.impl.EditingSides)3 Editor (com.intellij.openapi.editor.Editor)3 FragmentSide (com.intellij.openapi.diff.impl.highlighting.FragmentSide)2 LogicalPosition (com.intellij.openapi.editor.LogicalPosition)1