From 866bef8059591db9a17db71d66a1321b0ca25153 Mon Sep 17 00:00:00 2001 From: Patrick Bajao Date: Mon, 22 Jul 2019 13:25:24 +0800 Subject: Fix suggestion on lines that are not part of an MR Return the `text` as plain string in the response instead of including HTML tags but keep `rich_text` as is. The fix is to modify `Blob::UnfoldPresenter#diff_files` to map each raw diff line (limited by the range specified) to a corresponding line in an array of highlighted lines to use as `rich_text`. --- app/presenters/blob_presenter.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'app/presenters/blob_presenter.rb') diff --git a/app/presenters/blob_presenter.rb b/app/presenters/blob_presenter.rb index 91c9abe750b..2cf3278d240 100644 --- a/app/presenters/blob_presenter.rb +++ b/app/presenters/blob_presenter.rb @@ -4,7 +4,7 @@ class BlobPresenter < Gitlab::View::Presenter::Delegated presents :blob def highlight(plain: nil) - blob.load_all_data! if blob.respond_to?(:load_all_data!) + load_all_blob_data Gitlab::Highlight.highlight( blob.path, @@ -17,4 +17,10 @@ class BlobPresenter < Gitlab::View::Presenter::Delegated def web_url Gitlab::Routing.url_helpers.project_blob_url(blob.repository.project, File.join(blob.commit_id, blob.path)) end + + private + + def load_all_blob_data + blob.load_all_data! if blob.respond_to?(:load_all_data!) + end end -- cgit v1.2.1 From 46631e102366bd40bdb449b87fae3f10e992ee68 Mon Sep 17 00:00:00 2001 From: Patrick Bajao Date: Mon, 5 Aug 2019 17:44:13 +0800 Subject: Support selective highlighting of lines Instead of highlighting all lines when not all of them are needed, only highlight specific lines. The `BlobPresenter#highlight` method has been updated to support `since` and `to` params. These params will be used to limit the content to be highlighted. Modify `Gitlab::Highlight` to support `since` param which will then be used to determine the starting line number. --- app/presenters/blob_presenter.rb | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'app/presenters/blob_presenter.rb') 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 -- cgit v1.2.1 From 6d318af5f95cc4091b09f1b2f8ed9981f3a8b9c7 Mon Sep 17 00:00:00 2001 From: Patrick Bajao Date: Fri, 9 Aug 2019 00:13:09 +0000 Subject: Revert "Merge branch '65152-selective-highlight' into 'master'" This reverts merge request !31361 --- app/presenters/blob_presenter.rb | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) (limited to 'app/presenters/blob_presenter.rb') diff --git a/app/presenters/blob_presenter.rb b/app/presenters/blob_presenter.rb index f85c1a237a6..2cf3278d240 100644 --- a/app/presenters/blob_presenter.rb +++ b/app/presenters/blob_presenter.rb @@ -3,13 +3,12 @@ class BlobPresenter < Gitlab::View::Presenter::Delegated presents :blob - def highlight(since: nil, to: nil, plain: nil) + def highlight(plain: nil) load_all_blob_data Gitlab::Highlight.highlight( blob.path, - limited_blob_data(since: since, to: to), - since: since, + blob.data, language: blob.language_from_gitattributes, plain: plain ) @@ -24,18 +23,4 @@ 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 -- cgit v1.2.1