Make number of hidden unchanged lines and minimum number of context lines in diff user-configurable
Problem
In a diff of a file in Gitlab, there are currently three lines of context shown on either side of a changed line, for a total of seven lines for a single line of diff, and Gitlab hides the remainder of the file.
This often looks like this:
^ Show unchanged lines
-----------------------------------------------
13 Pre-context line 1
14 Pre-context line 2
15 Pre-context line 3
16 Line of code that actually changed
17 Post-context line 1
18 Post-context line 2
19 Post-context line 3
-----------------------------------------------
^ Show unchanged lines V
-----------------------------------------------
22 Pre-context line 1
23 Pre-context line 2
24 Pre-context line 3
25 Line of code that actually changed
26 Post-context line 1
27 Post-context line 2
28 Post-context line 3
-----------------------------------------------
...
As you can see, lines 20 and 21 are hidden by the ^ Show unchanged lines V
message.
Since the message ^ Show unchanged lines V
takes two lines of height in pixels and only hides two lines of code in this example, it saves no vertical space and requires extra clicks to see the hidden context.
Proposal
Therefore, I propose the following:
- A user preference setting for the minimum number of context lines to hide between diffs, and I suggest setting this to 10 as the default (the current value seems to be 2).
- This setting could be called "Hide more than this many unchanged lines in a diff"
- A user preference setting for the minimum number of context lines to show on either side of a changed line, and I suggest setting this to 3 (the current value) as the default.
- This setting could be called "Show at least this many lines on either side of a changed line in a diff"
Examples
1. Proposed defaults
- (1) Hide more than this many unchanged lines in a diff: 10
- (2) Show at least this many lines on either side of a changed line in a diff: 3
^ Show unchanged lines
-----------------------------------------------
13 Pre-context line 1
14 Pre-context line 2
15 Pre-context line 3
16 Line of code that actually changed
17 Post-context line 1
18 Post-context line 2
19 Post-context line 3
20 Additional line of context shown due to (1)
21 Additional line of context shown due to (1)
22 Pre-context line 1
23 Pre-context line 2
24 Pre-context line 3
25 Line of code that actually changed
26 Post-context line 1
27 Post-context line 2
28 Post-context line 3
-----------------------------------------------
2. Hyper-compressed
- (1) Hide more than this many unchanged lines in a diff: 0
- (2) Show at least this many lines on either side of a changed line in a diff: 0
^ Show unchanged lines
-----------------------------------------------
16 Line of code that actually changed
-----------------------------------------------
^ Show unchanged lines V
-----------------------------------------------
25 Line of code that actually changed
-----------------------------------------------
3. More context but no minimum unchanged lines diff
- (1) Hide more than this many unchanged lines in a diff: 0
- (2) Show at least this many lines on either side of a changed line in a diff: 4
^ Show unchanged lines
-----------------------------------------------
12 Additional pre-context line 1 due to (2)
13 Pre-context line 2
14 Pre-context line 3
15 pre-context line 4
16 Line of code that actually changed
17 Post-context line 1
18 Post-context line 2
19 Post-context line 3
20 Additional post-context line 4 due to 2
21 Additional pre-context line 1 due to 2
22 Pre-context line 2
23 Pre-context line 3
24 Pre-context line 4
25 Line of code that actually changed
26 Post-context line 1
27 Post-context line 2
28 Post-context line 3
29 Additional post-context line 4 due to (2)
-----------------------------------------------
Edited by 🤖 GitLab Bot 🤖