diff options
author | Tim Zallmann <tzallmann@gitlab.com> | 2017-10-05 11:54:46 +0200 |
---|---|---|
committer | Tim Zallmann <tzallmann@gitlab.com> | 2017-10-05 11:54:46 +0200 |
commit | 8b16f1074ddb6ea6a5404d37409ab81002f28d52 (patch) | |
tree | aca5904f189a8353fd56942b2c28a2bfbdab7923 | |
parent | 8d14a95638d7d6b52254b192b3e54296e22fddc3 (diff) | |
download | gitlab-ce-8b16f1074ddb6ea6a5404d37409ab81002f28d52.tar.gz |
Refactored Highlighting mechanism
4 files changed, 18 insertions, 16 deletions
diff --git a/app/assets/javascripts/line_highlighter.js b/app/assets/javascripts/line_highlighter.js index a16d00b5cef..9999b5a200c 100644 --- a/app/assets/javascripts/line_highlighter.js +++ b/app/assets/javascripts/line_highlighter.js @@ -54,12 +54,14 @@ LineHighlighter.prototype.bindEvents = function() { $fileHolder.on('highlight:line', this.highlightHash); }; -LineHighlighter.prototype.highlightHash = function() { - var range; +LineHighlighter.prototype.highlightHash = function(newHash) { + let range; + if (newHash) this._hash = newHash; + + this.clearHighlight(); if (this._hash !== '') { range = this.hashToRange(this._hash); - if (range[0]) { this.highlightRange(range); const lineSelector = `#L${range[0]}`; @@ -131,6 +133,7 @@ LineHighlighter.prototype.hashToRange = function(hash) { // // lineNumber - Line number to highlight LineHighlighter.prototype.highlightLine = function(lineNumber) { + console.log('LINE : ' + lineNumber); return $("#LC" + lineNumber).addClass(this.highlightLineClass); }; diff --git a/app/assets/javascripts/repo/components/repo_editor.vue b/app/assets/javascripts/repo/components/repo_editor.vue index f1acd339ad3..02d9c775046 100644 --- a/app/assets/javascripts/repo/components/repo_editor.vue +++ b/app/assets/javascripts/repo/components/repo_editor.vue @@ -64,11 +64,6 @@ const RepoEditor = { if (e.target.element.classList.contains('line-numbers')) { location.hash = `L${lineNumber}`; Store.setActiveLine(lineNumber); - - Helper.monacoInstance.setPosition({ - lineNumber: this.activeLine, - column: 1, - }); } }, }, @@ -101,6 +96,15 @@ const RepoEditor = { this.setupEditor(); } }, + + activeLine() { + if (Helper.monacoInstance) { + Helper.monacoInstance.setPosition({ + lineNumber: this.activeLine, + column: 1, + }); + } + }, }, computed: { shouldHideEditor() { diff --git a/app/assets/javascripts/repo/components/repo_preview.vue b/app/assets/javascripts/repo/components/repo_preview.vue index 2fe369a4693..514c7d9284c 100644 --- a/app/assets/javascripts/repo/components/repo_preview.vue +++ b/app/assets/javascripts/repo/components/repo_preview.vue @@ -28,6 +28,9 @@ export default { this.highlightFile(); }); }, + activeLine(e) { + this.lineHighlighter.highlightHash('#L' + Store.activeLine); + }, }, }; </script> diff --git a/app/assets/javascripts/repo/components/repo_sidebar.vue b/app/assets/javascripts/repo/components/repo_sidebar.vue index 9f58f63b850..2b0f1f661ff 100644 --- a/app/assets/javascripts/repo/components/repo_sidebar.vue +++ b/app/assets/javascripts/repo/components/repo_sidebar.vue @@ -42,14 +42,6 @@ export default { const lineNumber = Number(location.hash.substr(2)); if (!isNaN(lineNumber)) { Store.setActiveLine(lineNumber); - if (Store.isPreviewView() && document.getElementById(`L${lineNumber}`)) { - document.getElementById(`L${lineNumber}`).scrollIntoView(); - } else { - Helper.monacoInstance.setPosition({ - lineNumber: this.activeLine, - column: 1, - }); - } } } } else { |