From 5564fe31491a8a584b66feb6097742ec4025b8fa Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Fri, 12 Sep 2014 18:43:44 +0200 Subject: Add comments on the side-by-side diff. --- app/helpers/diff_helper.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'app/helpers/diff_helper.rb') diff --git a/app/helpers/diff_helper.rb b/app/helpers/diff_helper.rb index afe7447d4e2..8332b86d485 100644 --- a/app/helpers/diff_helper.rb +++ b/app/helpers/diff_helper.rb @@ -49,14 +49,16 @@ module DiffHelper next_line = diff_file.next_line(line.index) if next_line + next_line_code = generate_line_code(diff_file.file_path, next_line) next_type = next_line.type next_line = next_line.text end - line = [type, line_old, full_line, line_code, next_type, line_new] + line = [type, line_old, full_line, line_code, next_line_code, next_type, line_new] + if type == 'match' || type.nil? # line in the right panel is the same as in the left one - line = [type, line_old, full_line, line_code, type, line_new, full_line] + line = [type, line_old, full_line, line_code, line_code, type, line_new, full_line] lines.push(line) elsif type == 'old' if next_type == 'new' @@ -78,7 +80,7 @@ module DiffHelper next else # Change is only on the right side, left side has no change - line = [nil, nil, " ", line_code, type, line_new, full_line] + line = [nil, nil, " ", line_code, line_code, type, line_new, full_line] lines.push(line) end end @@ -97,4 +99,8 @@ module DiffHelper line end end + + def line_comments + @line_comments ||= @line_notes.group_by(&:line_code) + end end -- cgit v1.2.1 From e84861d510af63969a7ca09e4248426faf2dd345 Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Fri, 12 Sep 2014 19:40:04 +0200 Subject: Remove unecesarry array operations. --- app/helpers/diff_helper.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'app/helpers/diff_helper.rb') diff --git a/app/helpers/diff_helper.rb b/app/helpers/diff_helper.rb index 8332b86d485..c2ce6ed0fe4 100644 --- a/app/helpers/diff_helper.rb +++ b/app/helpers/diff_helper.rb @@ -36,7 +36,10 @@ module DiffHelper # Building array of lines # - # [left_type, left_line_number, left_line_content, line_code, right_line_type, right_line_number, right_line_content] + # [ + # left_type, left_line_number, left_line_content, left_line_code, + # right_line_type, right_line_number, right_line_content, right_line_code + # ] # diff_file.diff_lines.each do |line| @@ -54,23 +57,20 @@ module DiffHelper next_line = next_line.text end - line = [type, line_old, full_line, line_code, next_line_code, next_type, line_new] - if type == 'match' || type.nil? # line in the right panel is the same as in the left one - line = [type, line_old, full_line, line_code, line_code, type, line_new, full_line] + line = [type, line_old, full_line, line_code, type, line_new, full_line, line_code] lines.push(line) elsif type == 'old' if next_type == 'new' # Left side has text removed, right side has text added - line.push(next_line) + line = [type, line_old, full_line, line_code, next_type, line_new, next_line, next_line_code] lines.push(line) skip_next = true elsif next_type == 'old' || next_type.nil? # Left side has text removed, right side doesn't have any change - line.pop # remove the newline - line.push(nil) # no line number on the right panel - line.push(" ") # empty line on the right panel + # No next line code, no new line number, no new line text + line = [type, line_old, full_line, line_code, next_type, nil, " ", nil] lines.push(line) end elsif type == 'new' @@ -80,7 +80,7 @@ module DiffHelper next else # Change is only on the right side, left side has no change - line = [nil, nil, " ", line_code, line_code, type, line_new, full_line] + line = [nil, nil, " ", line_code, type, line_new, full_line, line_code] lines.push(line) end end -- cgit v1.2.1 From 9945e8c4244d90a0481846454355e02e80369aa2 Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Fri, 12 Sep 2014 19:51:44 +0200 Subject: Move organizing of comments to helper. --- app/helpers/diff_helper.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'app/helpers/diff_helper.rb') diff --git a/app/helpers/diff_helper.rb b/app/helpers/diff_helper.rb index c2ce6ed0fe4..cb50d89cba8 100644 --- a/app/helpers/diff_helper.rb +++ b/app/helpers/diff_helper.rb @@ -103,4 +103,18 @@ module DiffHelper def line_comments @line_comments ||= @line_notes.group_by(&:line_code) end + + def organize_comments(type_left, type_right, line_code_left, line_code_right) + comments_left = comments_right = nil + + unless type_left.nil? && type_right == 'new' + comments_left = line_comments[line_code_left] + end + + unless type_left.nil? && type_right.nil? + comments_right = line_comments[line_code_right] + end + + [comments_left, comments_right] + end end -- cgit v1.2.1