Enable adding draft on active line

Modified CodeMirrorDemo to highlight active line.

Added KeyMap from 'c' to a handler that adds drafts on active line,
edits existing drafts, or replies to published comments.

Modified lineOnOther() in LineMapper to return both the line number
and whether the line on the other side is aligned with the one on
this side. Added tests to verify.

Change-Id: I732ded8d76163a6b4dc76fcd45dbd9233090ce9c
This commit is contained in:
Michael Zhou
2013-06-28 16:27:18 -07:00
committed by Shawn Pearce
parent bcb6b6f149
commit 3227f3d80c
11 changed files with 273 additions and 50 deletions

View File

@@ -16,6 +16,7 @@ package com.google.gerrit.client.diff;
import static org.junit.Assert.assertEquals;
import com.google.gerrit.client.diff.LineMapper.LineOnOtherInfo;
import com.google.gerrit.common.changes.Side;
import org.junit.Test;
@@ -51,41 +52,55 @@ public class LineMapperTest {
public void testFindInCommon() {
LineMapper mapper = new LineMapper();
mapper.appendCommon(10);
assertEquals(9, mapper.lineOnOther(Side.PARENT, 9));
assertEquals(new LineOnOtherInfo(9, true),
mapper.lineOnOther(Side.PARENT, 9));
assertEquals(new LineOnOtherInfo(9, true),
mapper.lineOnOther(Side.REVISION, 9));
}
@Test
public void testFindAfterCommon() {
LineMapper mapper = new LineMapper();
mapper.appendCommon(10);
assertEquals(10, mapper.lineOnOther(Side.PARENT, 10));
assertEquals(new LineOnOtherInfo(10, true),
mapper.lineOnOther(Side.PARENT, 10));
assertEquals(new LineOnOtherInfo(10, true),
mapper.lineOnOther(Side.REVISION, 10));
}
@Test
public void testFindInInsertGap() {
LineMapper mapper = new LineMapper();
mapper.appendInsert(10);
assertEquals(-1, mapper.lineOnOther(Side.REVISION, 9));
assertEquals(new LineOnOtherInfo(-1, false),
mapper.lineOnOther(Side.REVISION, 9));
}
@Test
public void testFindAfterInsertGap() {
LineMapper mapper = new LineMapper();
mapper.appendInsert(10);
assertEquals(0, mapper.lineOnOther(Side.REVISION, 10));
assertEquals(new LineOnOtherInfo(0, true),
mapper.lineOnOther(Side.REVISION, 10));
assertEquals(new LineOnOtherInfo(10, true),
mapper.lineOnOther(Side.PARENT, 0));
}
@Test
public void testFindInDeleteGap() {
LineMapper mapper = new LineMapper();
mapper.appendDelete(10);
assertEquals(-1, mapper.lineOnOther(Side.PARENT, 9));
assertEquals(new LineOnOtherInfo(-1, false),
mapper.lineOnOther(Side.PARENT, 9));
}
@Test
public void testFindAfterDeleteGap() {
LineMapper mapper = new LineMapper();
mapper.appendDelete(10);
assertEquals(0, mapper.lineOnOther(Side.PARENT, 10));
assertEquals(new LineOnOtherInfo(0, true),
mapper.lineOnOther(Side.PARENT, 10));
assertEquals(new LineOnOtherInfo(10, true),
mapper.lineOnOther(Side.REVISION, 0));
}
}