diff options
author | Max Magorsch <arzano@gentoo.org> | 2020-07-11 02:01:03 +0000 |
---|---|---|
committer | Max Magorsch <arzano@gentoo.org> | 2020-07-11 02:01:03 +0000 |
commit | 7cb61f814cfd2a97bf27faea46af056ceba728d5 (patch) | |
tree | f6d8d638bf219db8029dc3023d987b93c277ce63 | |
parent | Highlight a selected line via #Lnn (diff) | |
download | frontend-7cb61f814cfd2a97bf27faea46af056ceba728d5.tar.gz frontend-7cb61f814cfd2a97bf27faea46af056ceba728d5.tar.bz2 frontend-7cb61f814cfd2a97bf27faea46af056ceba728d5.zip |
Add url paramter 'h' for further highlighting
One can use a comma sepearted list of either line numbers
or ranges of line numbers now to specify further lines
that should be highlighted. E.g.:
url_to_message?h=3-10,12,24-24
Signed-off-by: Max Magorsch <arzano@gentoo.org>
-rw-r--r-- | views/message.erb | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/views/message.erb b/views/message.erb index fa58a63..40c333a 100644 --- a/views/message.erb +++ b/views/message.erb @@ -86,11 +86,39 @@ </div> <script> + // highlight based on the specified reference in url var lineNumber = window.location.hash.substr(1).replace("L", ""); + highlightLine(lineNumber); - if(!isNaN(parseFloat(lineNumber)) && isFinite(lineNumber)){ - var lines = document.getElementById("ag-message-body").innerHTML.split("\n"); - lines[parseFloat(lineNumber) - 1] = '<div style="display: inline-block;background-color:#FFF3CD;">' + lines[parseFloat(lineNumber) - 1] + '</div>' - document.getElementById("ag-message-body").innerHTML = lines.join("\n"); + // highlight based on parameter "h" + var url = new URL(window.location.href); + var highlights = url.searchParams.get("h"); + + highlights.split(",").forEach(function(highlight){ + if(highlight.split("-").length == 2){ + var leftPart = highlight.split("-")[0]; + var rightPart = highlight.split("-")[1]; + if(isNumeric(leftPart) && isNumeric(rightPart) && parseFloat(leftPart) <= parseFloat(rightPart)){ + for(var i = parseFloat(leftPart); i <= parseFloat(rightPart); i++){ + highlightLine(i); + } + } + }else{ + highlightLine(highlight); + } + }) + + // utility functions + + function highlightLine(lineNumber) { + if(isNumeric(lineNumber)){ + var lines = document.getElementById("ag-message-body").innerHTML.split("\n"); + lines[parseFloat(lineNumber) - 1] = '<div style="display: inline-block;background-color:#FFF3CD;">' + lines[parseFloat(lineNumber) - 1] + '</div>' + document.getElementById("ag-message-body").innerHTML = lines.join("\n"); + } + } + + function isNumeric(possibleNumber) { + return !isNaN(parseFloat(possibleNumber)) && isFinite(possibleNumber) } </script>
\ No newline at end of file |