Commit 8b16f107 authored by Tim Zallmann's avatar Tim Zallmann

Refactored Highlighting mechanism

parent 8d14a956
...@@ -54,12 +54,14 @@ LineHighlighter.prototype.bindEvents = function() { ...@@ -54,12 +54,14 @@ LineHighlighter.prototype.bindEvents = function() {
$fileHolder.on('highlight:line', this.highlightHash); $fileHolder.on('highlight:line', this.highlightHash);
}; };
LineHighlighter.prototype.highlightHash = function() { LineHighlighter.prototype.highlightHash = function(newHash) {
var range; let range;
if (newHash) this._hash = newHash;
this.clearHighlight();
if (this._hash !== '') { if (this._hash !== '') {
range = this.hashToRange(this._hash); range = this.hashToRange(this._hash);
if (range[0]) { if (range[0]) {
this.highlightRange(range); this.highlightRange(range);
const lineSelector = `#L${range[0]}`; const lineSelector = `#L${range[0]}`;
...@@ -131,6 +133,7 @@ LineHighlighter.prototype.hashToRange = function(hash) { ...@@ -131,6 +133,7 @@ LineHighlighter.prototype.hashToRange = function(hash) {
// //
// lineNumber - Line number to highlight // lineNumber - Line number to highlight
LineHighlighter.prototype.highlightLine = function(lineNumber) { LineHighlighter.prototype.highlightLine = function(lineNumber) {
console.log('LINE : ' + lineNumber);
return $("#LC" + lineNumber).addClass(this.highlightLineClass); return $("#LC" + lineNumber).addClass(this.highlightLineClass);
}; };
......
...@@ -64,11 +64,6 @@ const RepoEditor = { ...@@ -64,11 +64,6 @@ const RepoEditor = {
if (e.target.element.classList.contains('line-numbers')) { if (e.target.element.classList.contains('line-numbers')) {
location.hash = `L${lineNumber}`; location.hash = `L${lineNumber}`;
Store.setActiveLine(lineNumber); Store.setActiveLine(lineNumber);
Helper.monacoInstance.setPosition({
lineNumber: this.activeLine,
column: 1,
});
} }
}, },
}, },
...@@ -101,6 +96,15 @@ const RepoEditor = { ...@@ -101,6 +96,15 @@ const RepoEditor = {
this.setupEditor(); this.setupEditor();
} }
}, },
activeLine() {
if (Helper.monacoInstance) {
Helper.monacoInstance.setPosition({
lineNumber: this.activeLine,
column: 1,
});
}
},
}, },
computed: { computed: {
shouldHideEditor() { shouldHideEditor() {
......
...@@ -28,6 +28,9 @@ export default { ...@@ -28,6 +28,9 @@ export default {
this.highlightFile(); this.highlightFile();
}); });
}, },
activeLine(e) {
this.lineHighlighter.highlightHash('#L' + Store.activeLine);
},
}, },
}; };
</script> </script>
......
...@@ -42,14 +42,6 @@ export default { ...@@ -42,14 +42,6 @@ export default {
const lineNumber = Number(location.hash.substr(2)); const lineNumber = Number(location.hash.substr(2));
if (!isNaN(lineNumber)) { if (!isNaN(lineNumber)) {
Store.setActiveLine(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 { } else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment