mirror of
https://github.com/seejohnrun/haste-server
synced 2025-08-21 01:13:08 -07:00
Use hash as line indicator
This commit is contained in:
parent
5014d7a088
commit
aea2329049
2 changed files with 17 additions and 8 deletions
|
@ -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();
|
||||
|
|
2
static/application.min.js
vendored
2
static/application.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue