diff options
author | Mark Chao <mchao@gitlab.com> | 2019-03-21 21:38:52 +0800 |
---|---|---|
committer | Mark Chao <mchao@gitlab.com> | 2019-03-21 23:08:29 +0800 |
commit | 8723f292552814cfe4566f213005e4e190fca456 (patch) | |
tree | 22b2a5bc1188ae7467d12c9e640fc1998a020741 /lib | |
parent | 8a59c9fdba4572cdfd60be6630d96fd37dc35654 (diff) | |
download | gitlab-ce-8723f292552814cfe4566f213005e4e190fca456.tar.gz |
Fix diff bottom expand button appears twice
This is a quick fix by only append match line once
when calling diff_lines_for_serializer multiple time.
Also enable feature by default
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/diff/file.rb | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/lib/gitlab/diff/file.rb b/lib/gitlab/diff/file.rb index dbee47a19ee..dce80bf21de 100644 --- a/lib/gitlab/diff/file.rb +++ b/lib/gitlab/diff/file.rb @@ -158,7 +158,10 @@ module Gitlab new_blob || old_blob end - attr_writer :highlighted_diff_lines + def highlighted_diff_lines=(value) + clear_memoization(:diff_lines_for_serializer) + @highlighted_diff_lines = value + end # Array of Gitlab::Diff::Line objects def diff_lines @@ -314,19 +317,21 @@ module Gitlab # This adds the bottom match line to the array if needed. It contains # the data to load more context lines. def diff_lines_for_serializer - lines = highlighted_diff_lines + strong_memoize(:diff_lines_for_serializer) do + lines = highlighted_diff_lines - return if lines.empty? - return if blob.nil? + next if lines.empty? + next if blob.nil? - last_line = lines.last + last_line = lines.last - if last_line.new_pos < total_blob_lines(blob) && !deleted_file? - match_line = Gitlab::Diff::Line.new("", 'match', nil, last_line.old_pos, last_line.new_pos) - lines.push(match_line) - end + if last_line.new_pos < total_blob_lines(blob) && !deleted_file? + match_line = Gitlab::Diff::Line.new("", 'match', nil, last_line.old_pos, last_line.new_pos) + lines.push(match_line) + end - lines + lines + end end def fully_expanded? |