Commit e565be241f39cf4119cb1d3e2668455ed11630fe

Authored by KennyTM~
1 parent fac50387

Show only ≤16 lines of code in a discussion (fix issue #2860).

app/helpers/commits_helper.rb
... ... @@ -57,6 +57,31 @@ module CommitsHelper
57 57 end
58 58 end
59 59  
  60 + def each_diff_line_near(diff, index, expected_line_code)
  61 + max_number_of_lines = 16
  62 +
  63 + prev_match_line = nil
  64 + prev_lines = []
  65 +
  66 + each_diff_line(diff, index) do |full_line, type, line_code, line_new, line_old|
  67 + line = [full_line, type, line_code, line_new, line_old]
  68 + if line_code != expected_line_code
  69 + if type == "match"
  70 + prev_lines.clear
  71 + prev_match_line = line
  72 + else
  73 + prev_lines.push(line)
  74 + prev_lines.shift if prev_lines.length >= max_number_of_lines
  75 + end
  76 + else
  77 + yield(prev_match_line) if !prev_match_line.nil?
  78 + prev_lines.each { |ln| yield(ln) }
  79 + yield(line)
  80 + break
  81 + end
  82 + end
  83 + end
  84 +
60 85 def image_diff_class(diff)
61 86 if diff.deleted_file
62 87 "deleted"
... ...
app/views/notes/_discussion_diff.html.haml
... ... @@ -9,7 +9,7 @@
9 9 %br/
10 10 .content
11 11 %table
12   - - each_diff_line(diff, note.diff_file_index) do |line, type, line_code, line_new, line_old|
  12 + - each_diff_line_near(diff, note.diff_file_index, note.line_code) do |line, type, line_code, line_new, line_old|
13 13 %tr.line_holder{ id: line_code }
14 14 - if type == "match"
15 15 %td.old_line= "..."
... ... @@ -22,4 +22,3 @@
22 22  
23 23 - if line_code == note.line_code
24 24 = render "notes/diff_notes_with_reply", notes: discussion_notes
25   - - break # cut off diff after notes
... ...