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
path: root/app
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@gitlab.com>2019-08-06 19:42:14 +0300
committerBob Van Landuyt <bob@gitlab.com>2019-08-06 19:42:14 +0300
commitd61dab914756854c0f5bef50306be77212ee15b4 (patch)
tree7e2396450980c36fefab904e8917a15ab034a343 /app
parent550e0d45c8e2237c68d834ca00cfc866fc78bb01 (diff)
parent46631e102366bd40bdb449b87fae3f10e992ee68 (diff)
Merge branch '65152-selective-highlight' into 'master'
Support selective highlighting of lines See merge request gitlab-org/gitlab-ce!31361
Diffstat (limited to 'app')
-rw-r--r--app/presenters/blob_presenter.rb19
-rw-r--r--app/presenters/blobs/unfold_presenter.rb23
2 files changed, 23 insertions, 19 deletions
diff --git a/app/presenters/blob_presenter.rb b/app/presenters/blob_presenter.rb
index 2cf3278d240..f85c1a237a6 100644
--- a/app/presenters/blob_presenter.rb
+++ b/app/presenters/blob_presenter.rb
@@ -3,12 +3,13 @@
class BlobPresenter < Gitlab::View::Presenter::Delegated
presents :blob
- def highlight(plain: nil)
+ def highlight(since: nil, to: nil, plain: nil)
load_all_blob_data
Gitlab::Highlight.highlight(
blob.path,
- blob.data,
+ limited_blob_data(since: since, to: to),
+ since: since,
language: blob.language_from_gitattributes,
plain: plain
)
@@ -23,4 +24,18 @@ class BlobPresenter < Gitlab::View::Presenter::Delegated
def load_all_blob_data
blob.load_all_data! if blob.respond_to?(:load_all_data!)
end
+
+ def limited_blob_data(since: nil, to: nil)
+ return blob.data if since.blank? || to.blank?
+
+ limited_blob_lines(since, to).join
+ end
+
+ def limited_blob_lines(since, to)
+ all_lines[since - 1..to - 1]
+ end
+
+ def all_lines
+ @all_lines ||= blob.data.lines
+ end
end
diff --git a/app/presenters/blobs/unfold_presenter.rb b/app/presenters/blobs/unfold_presenter.rb
index 21a1e1309e0..f4672d22fc9 100644
--- a/app/presenters/blobs/unfold_presenter.rb
+++ b/app/presenters/blobs/unfold_presenter.rb
@@ -21,20 +21,19 @@ module Blobs
load_all_blob_data
@subject = blob
- @all_lines = blob.data.lines
super(params)
if full?
- self.attributes = { since: 1, to: @all_lines.size, bottom: false, unfold: false, offset: 0, indent: 0 }
+ self.attributes = { since: 1, to: all_lines.size, bottom: false, unfold: false, offset: 0, indent: 0 }
end
end
# Returns an array of Gitlab::Diff::Line with match line added
def diff_lines
- diff_lines = lines.map.with_index do |line, index|
- full_line = limited_blob_lines[index].delete("\n")
+ diff_lines = limited_blob_lines(since, to).map.with_index do |line, index|
+ full_line = line.delete("\n")
- Gitlab::Diff::Line.new(full_line, nil, nil, nil, nil, rich_text: line)
+ Gitlab::Diff::Line.new(full_line, nil, nil, nil, nil, rich_text: lines[index])
end
add_match_line(diff_lines)
@@ -43,7 +42,7 @@ module Blobs
end
def lines
- @lines ||= limit(highlight.lines).map(&:html_safe)
+ @lines ||= highlight(since: since, to: to).lines.map(&:html_safe)
end
def match_line_text
@@ -59,7 +58,7 @@ module Blobs
def add_match_line(diff_lines)
return unless unfold?
- if bottom? && to < @all_lines.size
+ if bottom? && to < all_lines.size
old_pos = to - offset
new_pos = to
elsif since != 1
@@ -73,15 +72,5 @@ module Blobs
bottom? ? diff_lines.push(match_line) : diff_lines.unshift(match_line)
end
-
- def limited_blob_lines
- @limited_blob_lines ||= limit(@all_lines)
- end
-
- def limit(lines)
- return lines if full?
-
- lines[since - 1..to - 1]
- end
end
end