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

File diff suppressed because one or more lines are too long