Commit 63f18fb4 authored by Phil Hughes's avatar Phil Hughes

Fixes outdated diff lines returning incorrect results

The outdated diff lines service will sometimes return
incorrect results if the commented line number no longer exists in the
diff.
So instead we find the old diff line and then find the _next_ new
or unchanged line and use that as the index to display
the correct diff.
parent 30cfc3c3
...@@ -15,12 +15,22 @@ module MergeRequests ...@@ -15,12 +15,22 @@ module MergeRequests
def execute def execute
line_position = position.line_range["end"] || position.line_range["start"] line_position = position.line_range["end"] || position.line_range["start"]
diff_line_index = diff_lines.find_index do |l| found_line = false
if line_position["new_line"] diff_line_index = -1
l.new_line == line_position["new_line"] diff_lines.each_with_index do |l, i|
elsif line_position["old_line"] if found_line
l.old_line == line_position["old_line"] if !l.type
break
elsif l.type == 'new'
diff_line_index = i
break
end
else
# Find the old line
found_line = l.old_line == line_position["new_line"]
end end
diff_line_index = i
end end
initial_line_index = [diff_line_index - OVERFLOW_LINES_COUNT, 0].max initial_line_index = [diff_line_index - OVERFLOW_LINES_COUNT, 0].max
last_line_index = [diff_line_index + OVERFLOW_LINES_COUNT, diff_lines.length].min last_line_index = [diff_line_index + OVERFLOW_LINES_COUNT, diff_lines.length].min
......
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