Commit 83e4fc18 authored by Douwe Maan's avatar Douwe Maan

Refactor highlighting lines

parent 3a1d0535
...@@ -32,23 +32,8 @@ module Gitlab ...@@ -32,23 +32,8 @@ module Gitlab
def highlight def highlight
return [] if @lines.empty? return [] if @lines.empty?
extract_line_prefixes
update_diff_lines
end
private
def text_lines
@text_lines ||= @lines.map(&:text)
end
def extract_line_prefixes
@diff_line_prefixes ||= text_lines.map { |line| line.sub!(/\A((\+|\-))/, '');$1 }
end
def update_diff_lines
@lines.each_with_index do |line, i| @lines.each_with_index do |line, i|
line_prefix = @diff_line_prefixes[i] || ' ' line_prefix = line.text.match(/\A([+-])/) ? $1 : ' '
# ignore highlighting for "match" lines # ignore highlighting for "match" lines
next if line.type == 'match' next if line.type == 'match'
...@@ -62,24 +47,18 @@ module Gitlab ...@@ -62,24 +47,18 @@ module Gitlab
# Only update text if line is found. This will prevent # Only update text if line is found. This will prevent
# issues with submodules given the line only exists in diff content. # issues with submodules given the line only exists in diff content.
line.text = highlighted_line.sub(/\A\s/, line_prefix).html_safe if highlighted_line line.text = highlighted_line.insert(0, line_prefix).html_safe if highlighted_line
end end
@lines @lines
end end
def old_lines def old_lines
@old_lines ||= begin @old_lines ||= self.class.process_file(diff_repository, diff_old_ref, diff_old_path)
lines = self.class.process_file(diff_repository, diff_old_ref, diff_old_path)
lines.map! { |line| " #{line}" }
end
end end
def new_lines def new_lines
@new_lines ||= begin @new_lines ||= self.class.process_file(diff_repository, diff_new_ref, diff_new_path)
lines = self.class.process_file(diff_repository, diff_new_ref, diff_new_path)
lines.map! { |line| " #{line}" }
end
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment