Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/word_diff/chunk_collection.rb')
-rw-r--r--lib/gitlab/word_diff/chunk_collection.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/gitlab/word_diff/chunk_collection.rb b/lib/gitlab/word_diff/chunk_collection.rb
index dd388f75302..d5c3e59d405 100644
--- a/lib/gitlab/word_diff/chunk_collection.rb
+++ b/lib/gitlab/word_diff/chunk_collection.rb
@@ -18,6 +18,27 @@ module Gitlab
def reset
@chunks = []
end
+
+ def marker_ranges
+ start = 0
+
+ @chunks.each_with_object([]) do |element, ranges|
+ mode = mode_for_element(element)
+
+ ranges << Gitlab::MarkerRange.new(start, start + element.length - 1, mode: mode) if mode
+
+ start += element.length
+ end
+ end
+
+ private
+
+ def mode_for_element(element)
+ return Gitlab::MarkerRange::DELETION if element.removed?
+ return Gitlab::MarkerRange::ADDITION if element.added?
+
+ nil
+ end
end
end
end