Commit 9109a207589c3a3d085005ee87049bba6aeecc1a
1 parent
62635983
Exists in
master
and in
4 other branches
Improve commit diff
* show highlights when replace empty line with content * show inline diff when replace line with spaces with content
Showing
1 changed file
with
14 additions
and
2 deletions
Show diff stats
lib/gitlab/inline_diff.rb
@@ -13,6 +13,9 @@ module Gitlab | @@ -13,6 +13,9 @@ module Gitlab | ||
13 | second_line = diff_arr[index+2] | 13 | second_line = diff_arr[index+2] |
14 | max_length = [first_line.size, second_line.size].max | 14 | max_length = [first_line.size, second_line.size].max |
15 | 15 | ||
16 | + # Skip inline diff if empty line was replaced with content | ||
17 | + next if first_line == "-\n" | ||
18 | + | ||
16 | first_the_same_symbols = 0 | 19 | first_the_same_symbols = 0 |
17 | (0..max_length + 1).each do |i| | 20 | (0..max_length + 1).each do |i| |
18 | first_the_same_symbols = i - 1 | 21 | first_the_same_symbols = i - 1 |
@@ -20,10 +23,19 @@ module Gitlab | @@ -20,10 +23,19 @@ module Gitlab | ||
20 | break | 23 | break |
21 | end | 24 | end |
22 | end | 25 | end |
26 | + | ||
23 | first_token = first_line[0..first_the_same_symbols][1..-1] | 27 | first_token = first_line[0..first_the_same_symbols][1..-1] |
24 | start = first_token + START | 28 | start = first_token + START |
25 | - diff_arr[index+1].sub!(first_token, first_token => start) | ||
26 | - diff_arr[index+2].sub!(first_token, first_token => start) | 29 | + |
30 | + if first_token.empty? | ||
31 | + # In case if we remove string of spaces in commit | ||
32 | + diff_arr[index+1].sub!("-", "-" => "-#{START}") | ||
33 | + diff_arr[index+2].sub!("+", "+" => "+#{START}") | ||
34 | + else | ||
35 | + diff_arr[index+1].sub!(first_token, first_token => start) | ||
36 | + diff_arr[index+2].sub!(first_token, first_token => start) | ||
37 | + end | ||
38 | + | ||
27 | last_the_same_symbols = 0 | 39 | last_the_same_symbols = 0 |
28 | (1..max_length + 1).each do |i| | 40 | (1..max_length + 1).each do |i| |
29 | last_the_same_symbols = -i | 41 | last_the_same_symbols = -i |