Use hash as line indicator

This commit is contained in:
Kenox 2022-11-03 18:35:08 +01:00
commit aea2329049
2 changed files with 17 additions and 8 deletions

View file

@ -178,6 +178,15 @@ haste.prototype.addLineNumbers = function(lineCount) {
let line = i + 1; let line = i + 1;
div.href = '#' + line; div.href = '#' + line;
div.onclick = function() { div.onclick = function() {
highlightLine(line);
}
let text = document.createTextNode(line.toString());
div.appendChild(text);
document.body.appendChild(div)
}
};
function highlightLine(line) {
var box = document.getElementById("box"); var box = document.getElementById("box");
// create highlight div // create highlight div
removeElementsByClass('highlight'); removeElementsByClass('highlight');
@ -185,12 +194,7 @@ haste.prototype.addLineNumbers = function(lineCount) {
highlight.classList.add('highlight'); highlight.classList.add('highlight');
highlight.style.marginTop = ((line - 1) * 16) + 'px'; highlight.style.marginTop = ((line - 1) * 16) + 'px';
box.insertBefore(highlight, box.firstChild); box.insertBefore(highlight, box.firstChild);
} }
let text = document.createTextNode(line.toString());
div.appendChild(text);
document.body.appendChild(div)
}
};
function removeElementsByClass(className){ function removeElementsByClass(className){
const elements = document.getElementsByClassName(className); const elements = document.getElementsByClassName(className);
@ -225,6 +229,11 @@ haste.prototype.loadDocument = function(key) {
_this.$textarea.val('').hide(); _this.$textarea.val('').hide();
_this.$box.show().focus(); _this.$box.show().focus();
_this.addLineNumbers(ret.lineCount); _this.addLineNumbers(ret.lineCount);
if(window.location.hash) {
const hash = window.location.hash.substring(1);
highlightLine(hash)
}
} }
else { else {
_this.newDocument(); _this.newDocument();

File diff suppressed because one or more lines are too long