Commit 9109a207589c3a3d085005ee87049bba6aeecc1a

Authored by Dmitriy Zaporozhets
1 parent 62635983

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 13 second_line = diff_arr[index+2]
14 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 19 first_the_same_symbols = 0
17 20 (0..max_length + 1).each do |i|
18 21 first_the_same_symbols = i - 1
... ... @@ -20,10 +23,19 @@ module Gitlab
20 23 break
21 24 end
22 25 end
  26 +
23 27 first_token = first_line[0..first_the_same_symbols][1..-1]
24 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 39 last_the_same_symbols = 0
28 40 (1..max_length + 1).each do |i|
29 41 last_the_same_symbols = -i
... ...