Search in sources :

Example 1 with LineOnOtherInfo

use of com.google.gerrit.client.diff.LineMapper.LineOnOtherInfo in project gerrit by GerritCodeReview.

the class SideBySide method updateActiveLine.

@Override
Runnable updateActiveLine(CodeMirror cm) {
    CodeMirror other = otherCm(cm);
    return () -> {
        // The rendering of active lines has to be deferred. Reflow
        // caused by adding and removing styles chokes Firefox when arrow
        // key (or j/k) is held down. Performance on Chrome is fine
        // without the deferral.
        //
        Scheduler.get().scheduleDeferred(new ScheduledCommand() {

            @Override
            public void execute() {
                operation(() -> {
                    LineHandle handle = cm.getLineHandleVisualStart(cm.getCursor("end").line());
                    if (!cm.extras().activeLine(handle)) {
                        return;
                    }
                    LineOnOtherInfo info = lineOnOther(cm.side(), cm.getLineNumber(handle));
                    if (info.isAligned()) {
                        other.extras().activeLine(other.getLineHandle(info.getLine()));
                    } else {
                        other.extras().clearActiveLine();
                    }
                });
            }
        });
    };
}
Also used : LineHandle(net.codemirror.lib.CodeMirror.LineHandle) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) LineOnOtherInfo(com.google.gerrit.client.diff.LineMapper.LineOnOtherInfo) CodeMirror(net.codemirror.lib.CodeMirror)

Example 2 with LineOnOtherInfo

use of com.google.gerrit.client.diff.LineMapper.LineOnOtherInfo in project gerrit by GerritCodeReview.

the class UnifiedCommentManager method newDraft.

@Override
void newDraft(CodeMirror cm) {
    if (cm.somethingSelected()) {
        FromTo fromTo = adjustSelection(cm);
        Pos from = fromTo.from();
        Pos to = fromTo.to();
        Unified unified = (Unified) host;
        UnifiedChunkManager manager = unified.getChunkManager();
        LineRegionInfo fromInfo = unified.getLineRegionInfoFromCmLine(from.line());
        LineRegionInfo toInfo = unified.getLineRegionInfoFromCmLine(to.line());
        DisplaySide side = toInfo.getSide();
        // start line to be on the same side as the end line.
        if ((fromInfo.type == RegionType.INSERT || fromInfo.type == RegionType.COMMON) && toInfo.type == RegionType.DELETE) {
            LineOnOtherInfo infoOnSideA = manager.lineMapper.lineOnOther(DisplaySide.B, fromInfo.line);
            int startLineOnSideA = infoOnSideA.getLine();
            if (infoOnSideA.isAligned()) {
                from.line(startLineOnSideA);
            } else {
                from.line(startLineOnSideA + 1);
            }
            from.ch(0);
            to.line(toInfo.line);
        } else if (fromInfo.type == RegionType.DELETE && toInfo.type == RegionType.INSERT) {
            LineOnOtherInfo infoOnSideB = manager.lineMapper.lineOnOther(DisplaySide.A, fromInfo.line);
            int startLineOnSideB = infoOnSideB.getLine();
            if (infoOnSideB.isAligned()) {
                from.line(startLineOnSideB);
            } else {
                from.line(startLineOnSideB + 1);
            }
            from.ch(0);
            to.line(toInfo.line);
        } else if (fromInfo.type == RegionType.DELETE && toInfo.type == RegionType.COMMON) {
            int toLineOnSideA = manager.lineMapper.lineOnOther(DisplaySide.B, toInfo.line).getLine();
            from.line(fromInfo.line);
            // Force the end line to be on the same side as the start line.
            to.line(toLineOnSideA);
            side = DisplaySide.A;
        } else {
            // Common case
            from.line(fromInfo.line);
            to.line(toInfo.line);
        }
        addDraftBox(side, CommentInfo.create(getPath(), getStoredSideFromDisplaySide(side), to.line() + 1, CommentRange.create(fromTo), false)).setEdit(true);
        cm.setCursor(Pos.create(host.getCmLine(to.line(), side), to.ch()));
        cm.setSelection(cm.getCursor());
    } else {
        int cmLine = cm.getLineNumber(cm.extras().activeLine());
        LineRegionInfo info = ((Unified) host).getLineRegionInfoFromCmLine(cmLine);
        insertNewDraft(info.getSide(), cmLine + 1);
    }
}
Also used : Pos(net.codemirror.lib.Pos) FromTo(net.codemirror.lib.TextMarker.FromTo) LineOnOtherInfo(com.google.gerrit.client.diff.LineMapper.LineOnOtherInfo) LineRegionInfo(com.google.gerrit.client.diff.UnifiedChunkManager.LineRegionInfo)

Example 3 with LineOnOtherInfo

use of com.google.gerrit.client.diff.LineMapper.LineOnOtherInfo in project gerrit by GerritCodeReview.

the class LineMapperTest method findInInsertGap.

@Test
public void findInInsertGap() {
    LineMapper mapper = new LineMapper();
    mapper.appendInsert(10);
    assertEquals(new LineOnOtherInfo(-1, false), mapper.lineOnOther(DisplaySide.B, 9));
}
Also used : LineOnOtherInfo(com.google.gerrit.client.diff.LineMapper.LineOnOtherInfo) Test(org.junit.Test)

Example 4 with LineOnOtherInfo

use of com.google.gerrit.client.diff.LineMapper.LineOnOtherInfo in project gerrit by GerritCodeReview.

the class LineMapperTest method findAfterInsertGap.

@Test
public void findAfterInsertGap() {
    LineMapper mapper = new LineMapper();
    mapper.appendInsert(10);
    assertEquals(new LineOnOtherInfo(0, true), mapper.lineOnOther(DisplaySide.B, 10));
    assertEquals(new LineOnOtherInfo(10, true), mapper.lineOnOther(DisplaySide.A, 0));
}
Also used : LineOnOtherInfo(com.google.gerrit.client.diff.LineMapper.LineOnOtherInfo) Test(org.junit.Test)

Example 5 with LineOnOtherInfo

use of com.google.gerrit.client.diff.LineMapper.LineOnOtherInfo in project gerrit by GerritCodeReview.

the class LineMapperTest method findInCommon.

@Test
public void findInCommon() {
    LineMapper mapper = new LineMapper();
    mapper.appendCommon(10);
    assertEquals(new LineOnOtherInfo(9, true), mapper.lineOnOther(DisplaySide.A, 9));
    assertEquals(new LineOnOtherInfo(9, true), mapper.lineOnOther(DisplaySide.B, 9));
}
Also used : LineOnOtherInfo(com.google.gerrit.client.diff.LineMapper.LineOnOtherInfo) Test(org.junit.Test)

Aggregations

LineOnOtherInfo (com.google.gerrit.client.diff.LineMapper.LineOnOtherInfo)9 Test (org.junit.Test)7 LineRegionInfo (com.google.gerrit.client.diff.UnifiedChunkManager.LineRegionInfo)1 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)1 CodeMirror (net.codemirror.lib.CodeMirror)1 LineHandle (net.codemirror.lib.CodeMirror.LineHandle)1 Pos (net.codemirror.lib.Pos)1 FromTo (net.codemirror.lib.TextMarker.FromTo)1