From 82d0221b632fbb2e7711678b11e9ff26214d9d69 Mon Sep 17 00:00:00 2001
From: Annabel Dunstone <annabel.dunstone@gmail.com>
Date: Wed, 13 Apr 2016 15:33:44 -0500
Subject: [PATCH] Add line type conditional to diff line helper

---
 app/assets/stylesheets/pages/diff.scss         | 18 +++++++++++-------
 app/helpers/diff_helper.rb                     |  6 ++++--
 app/views/projects/diffs/_line.html.haml       |  2 +-
 .../projects/notes/discussions/_diff.html.haml |  2 +-
 4 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/app/assets/stylesheets/pages/diff.scss b/app/assets/stylesheets/pages/diff.scss
index bd7640db3b7..77d7a3024d5 100644
--- a/app/assets/stylesheets/pages/diff.scss
+++ b/app/assets/stylesheets/pages/diff.scss
@@ -67,14 +67,18 @@
         line-height: $code_line_height;
         font-size: $code_font_size;
 
-        &.noteable_line.old:before {
-          content: '-';
-          position: absolute;
+        &.noteable_line.old {
+          &:before {
+            content: '-';
+            position: absolute;
+          }
         }
 
-        &.noteable_line.new:before {
-          content: '+';
-          position: absolute;
+        &.noteable_line.new {
+          &:before {
+            content: '+';
+            position: absolute;
+          }
         }
 
         span {
@@ -406,7 +410,7 @@
   .diff-line-num:not(.js-unfold-bottom) {
     a {
       &:before {
-          content: attr(data-linenumber);
+        content: attr(data-linenumber);
       }
     }
   }
diff --git a/app/helpers/diff_helper.rb b/app/helpers/diff_helper.rb
index f1e213b34e8..0504cfb7591 100644
--- a/app/helpers/diff_helper.rb
+++ b/app/helpers/diff_helper.rb
@@ -40,11 +40,13 @@ module DiffHelper
     (unfold) ? 'unfold js-unfold' : ''
   end
 
-  def diff_line_content(line)
+  def diff_line_content(line, line_type = nil)
     if line.blank?
       " &nbsp;".html_safe
     else
-      line[0] = ''
+      if line_type == 'new' || line_type == 'old'
+        line[0] = " "
+      end
       line
     end
   end
diff --git a/app/views/projects/diffs/_line.html.haml b/app/views/projects/diffs/_line.html.haml
index 2dc6f548437..6c5602acd43 100644
--- a/app/views/projects/diffs/_line.html.haml
+++ b/app/views/projects/diffs/_line.html.haml
@@ -23,4 +23,4 @@
         = link_text
       - else
         = link_to "", "##{line_code}", id: line_code, data: { linenumber: link_text }
-    %td.line_content{class: "noteable_line #{type} #{line_code}", data: { line_code: line_code }}= diff_line_content(line.text)
+    %td.line_content{class: "noteable_line #{type} #{line_code}", data: { line_code: line_code }}= diff_line_content(line.text, type)
diff --git a/app/views/projects/notes/discussions/_diff.html.haml b/app/views/projects/notes/discussions/_diff.html.haml
index 6abfb3abc3b..9fd9d5bb2aa 100644
--- a/app/views/projects/notes/discussions/_diff.html.haml
+++ b/app/views/projects/notes/discussions/_diff.html.haml
@@ -22,7 +22,7 @@
             - else
               %td.old_line.diff-line-num{data: {linenumber: raw(type == "new" ? "&nbsp;" : line.old_pos)}}
               %td.new_line.diff-line-num{data: {linenumber: raw(type == "old" ? "&nbsp;" : line.new_pos)}}
-              %td.line_content{class: "noteable_line #{type} #{line_code}", line_code: line_code}= diff_line_content(line.text)
+              %td.line_content{class: "noteable_line #{type} #{line_code}", line_code: line_code}= diff_line_content(line.text, type)
 
               - if line_code == note.line_code
                 = render "projects/notes/diff_notes_with_reply", notes: discussion_notes
-- 
GitLab