Do not collapse lines of code with less than 4 lines

Before the threshold was 1 lines. This is now changed to 3 lines.
The thinking is that a user would always prefer to just see 3 lines
instead of having them collapsed.

Change-Id: I0ff26c1f39bb517105c2fa380b63dddec894a815
This commit is contained in:
Ben Rohlfs
2020-11-30 12:12:56 +01:00
parent 0fc9c2547f
commit 22b9e70e27
2 changed files with 8 additions and 5 deletions

View File

@@ -83,8 +83,9 @@ export function hideInContextControl(
const numHidden = hiddenEnd - hiddenStart;
// Only collapse if there is more than 1 line to be hidden.
if (numHidden > 1) {
// Showing a context control row for less than 4 lines does not make much,
// because then that row would consume as much space as the collapsed code.
if (numHidden > 3) {
if (hiddenStart) {
[before, hidden] = _splitCommonGroups(hidden, hiddenStart);
}

View File

@@ -122,17 +122,19 @@ suite('gr-diff-group tests', () => {
new GrDiffLine(GrDiffLineType.ADD, 0, 11),
new GrDiffLine(GrDiffLineType.REMOVE, 10),
new GrDiffLine(GrDiffLineType.ADD, 0, 12),
new GrDiffLine(GrDiffLineType.REMOVE, 11),
new GrDiffLine(GrDiffLineType.ADD, 0, 13),
]),
new GrDiffGroup(GrDiffGroupType.BOTH, [
new GrDiffLine(GrDiffLineType.BOTH, 11, 13),
new GrDiffLine(GrDiffLineType.BOTH, 12, 14),
new GrDiffLine(GrDiffLineType.BOTH, 13, 15),
new GrDiffLine(GrDiffLineType.BOTH, 14, 16),
]),
];
});
test('hides hidden groups in context control', () => {
const collapsedGroups = hideInContextControl(groups, 3, 6);
const collapsedGroups = hideInContextControl(groups, 3, 7);
assert.equal(collapsedGroups.length, 3);
assert.equal(collapsedGroups[0], groups[0]);
@@ -145,7 +147,7 @@ suite('gr-diff-group tests', () => {
});
test('splits partially hidden groups', () => {
const collapsedGroups = hideInContextControl(groups, 4, 7);
const collapsedGroups = hideInContextControl(groups, 4, 8);
assert.equal(collapsedGroups.length, 4);
assert.equal(collapsedGroups[0], groups[0]);