#528 Linking to particular line should highlight it
Closed: Fixed None Opened 8 years ago by lsedlar.

A link to a particular line in a source file should not only scroll to it, but also somehow indicate which line it is.

Example link:
https://pagure.io/pagure/blob/master/f/createdb.py#_11

I have implemented this as a user script, but having it work automatically would be nice (esp. not having to inject a stylesheet). A useful extension would be to enable linking to a line range (example, Shift+click selects range).

function updateHighlight() {
  var cls = "highlighted-line";
  $('.' + cls).removeClass(cls)
  if (location.hash !== '') {
    var lineno = location.hash.substr(2);
    $('[data-line-number=' + lineno + ']').parents('tr').addClass(cls);
  }
}
$(document).ready(function () {
  $("head").append("<style>.highlighted-line{background-color:#FFFABA;}</style>");
  updateHighlight();
});
$(window).on('hashchange', updateHighlight);

Login to comment on this ticket.

Metadata