summaryrefslogtreecommitdiff
path: root/app/assets/javascripts
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-23 09:09:42 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-23 09:09:42 +0000
commite4bf776a8829e5186a0f63603c0be627b891d80e (patch)
tree537fe714bd336bfee9f30b101a5072950a04a62a /app/assets/javascripts
parent1635eacd2a9293cd04d21e82def6e2c14ed01242 (diff)
downloadgitlab-ce-e4bf776a8829e5186a0f63603c0be627b891d80e.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts')
-rw-r--r--app/assets/javascripts/pages/search/show/highlight_blob_search_result.js15
-rw-r--r--app/assets/javascripts/pages/search/show/search.js2
2 files changed, 17 insertions, 0 deletions
diff --git a/app/assets/javascripts/pages/search/show/highlight_blob_search_result.js b/app/assets/javascripts/pages/search/show/highlight_blob_search_result.js
new file mode 100644
index 00000000000..e17c87735b4
--- /dev/null
+++ b/app/assets/javascripts/pages/search/show/highlight_blob_search_result.js
@@ -0,0 +1,15 @@
+export default () => {
+ const highlightLineClass = 'hll';
+ const contentBody = document.getElementById('content-body');
+ const searchTerm = contentBody.querySelector('.js-search-input').value.toLowerCase();
+ const blobs = contentBody.querySelectorAll('.blob-result');
+
+ blobs.forEach(blob => {
+ const lines = blob.querySelectorAll('.line');
+ lines.forEach(line => {
+ if (line.textContent.toLowerCase().includes(searchTerm)) {
+ line.classList.add(highlightLineClass);
+ }
+ });
+ });
+};
diff --git a/app/assets/javascripts/pages/search/show/search.js b/app/assets/javascripts/pages/search/show/search.js
index dff9d855b67..4050f2f13f1 100644
--- a/app/assets/javascripts/pages/search/show/search.js
+++ b/app/assets/javascripts/pages/search/show/search.js
@@ -5,9 +5,11 @@ import Api from '~/api';
import { __ } from '~/locale';
import Project from '~/pages/projects/project';
import refreshCounts from './refresh_counts';
+import setHighlightClass from './highlight_blob_search_result';
export default class Search {
constructor() {
+ setHighlightClass();
const $groupDropdown = $('.js-search-group-dropdown');
const $projectDropdown = $('.js-search-project-dropdown');