Prevent single-line collapsed common groups

When the diff processor collapses shared groups based on the user
context preference, it would sometimes collapse a single line, resulting
in a common group labeled "Show 1 common line" which takes up exactly
as much space in the diff view as the line itself. Moreover, the GWT UI
does not collapse single line common sections in this way (but does when
there are two or more lines).

Sets the threshold to collapse at least two lines and encodes this in a
test.

Bug: Issue 4721
Change-Id: I8a3a8556fd66a313eacc361379612c700d7ae070
This commit is contained in:
Wyatt Allen
2016-10-12 10:45:42 -07:00
parent 1fb45813a1
commit 9d8649bfa1
2 changed files with 12 additions and 1 deletions

View File

@@ -258,7 +258,7 @@
}
// If there is a range to hide.
if (context !== WHOLE_FILE && hiddenRange[1] - hiddenRange[0] > 0) {
if (context !== WHOLE_FILE && hiddenRange[1] - hiddenRange[0] > 1) {
var linesBeforeCtx = lines.slice(0, hiddenRange[0]);
var hiddenLines = lines.slice(hiddenRange[0], hiddenRange[1]);
var linesAfterCtx = lines.slice(hiddenRange[1]);

View File

@@ -511,6 +511,17 @@ limitations under the License.
assert.equal(result[0].lines.length, rows.length);
});
test('_sharedGroupsFromRows no single line collapse', function() {
rows = rows.slice(0, 7);
var context = 3;
var result = element._sharedGroupsFromRows(
rows, context, 10, 100);
// Results in one uncollapsed group with all rows.
assert.equal(result.length, 1, 'Results in one group');
assert.equal(result[0].lines.length, rows.length);
});
test('_deltaLinesFromRows', function() {
var startLineNum = 10;
var result = element._deltaLinesFromRows(GrDiffLine.Type.ADD, rows,