Commit c71892e1 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Even more refactoring to inline_diff.rb

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent c903f23f
...@@ -17,6 +17,16 @@ module Gitlab ...@@ -17,6 +17,16 @@ module Gitlab
next if first_line == "-\n" next if first_line == "-\n"
first_token = find_first_token(first_line, second_line) first_token = find_first_token(first_line, second_line)
apply_first_token(diff_arr, index, first_token)
last_token = find_last_token(first_line, second_line, first_token)
apply_last_token(diff_arr, index, last_token)
end
diff_arr
end
def apply_first_token(diff_arr, index, first_token)
start = first_token + START start = first_token + START
if first_token.empty? if first_token.empty?
...@@ -27,9 +37,9 @@ module Gitlab ...@@ -27,9 +37,9 @@ module Gitlab
diff_arr[index+1].sub!(first_token, first_token => start) diff_arr[index+1].sub!(first_token, first_token => start)
diff_arr[index+2].sub!(first_token, first_token => start) diff_arr[index+2].sub!(first_token, first_token => start)
end end
end
last_token = find_last_token(first_line, second_line, first_token) def apply_last_token(diff_arr, index, last_token)
# This is tricky: escape backslashes so that `sub` doesn't interpret them # This is tricky: escape backslashes so that `sub` doesn't interpret them
# as backreferences. Regexp.escape does NOT do the right thing. # as backreferences. Regexp.escape does NOT do the right thing.
replace_token = FINISH + last_token.gsub(/\\/, '\&\&') replace_token = FINISH + last_token.gsub(/\\/, '\&\&')
...@@ -37,9 +47,6 @@ module Gitlab ...@@ -37,9 +47,6 @@ module Gitlab
diff_arr[index+2].sub!(/#{Regexp.escape(last_token)}$/, replace_token) diff_arr[index+2].sub!(/#{Regexp.escape(last_token)}$/, replace_token)
end end
diff_arr
end
def find_first_token(first_line, second_line) def find_first_token(first_line, second_line)
max_length = [first_line.size, second_line.size].max max_length = [first_line.size, second_line.size].max
first_the_same_symbols = 0 first_the_same_symbols = 0
......
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