[PATCH v5 0/6] line range highlight

Andy Green andy at warmcat.com
Tue Jun 26 13:25:02 CEST 2018

The following series adds the ability to direct the browser
to highlight specific lines and ranges of lines in
/tree/, /source/, and /blame/ views, using the existing

As part of the implementation it adds a new cgit.js file
that is included in cgit page <head> along with a new
config "js" to specify its url, defaulting to "/cgit.js".
It can be disabled by setting the "js" config to an empty

Highlit lines or ranges are centred vertically rather than
the default of scrolled to the top of the browser window

You can click on the line number links to highlight
individual lines, or line ranges when an individual line
is already highlit.  If a range is highlit, clicking on
a line number link clears the range and just highlights
that line again.

When you click on a line number link, a clipboard icon
appears for 5s on the left of the link.  If you click on
this icon, the current #URL is copied to the clipboard.

CSS transitions are used throughout.

v5 cleans the js up a bit and disables the browser
response to clicking on a #URL, stopping the scroll position
jumping around.

It also switches to listening for window.load to apply the
initial highlight.  Because wait on the DOM load is racy
for the layout having access to header image size... the
page vertical position can change after DOM load is complete.

You can find the patches as a usable tree here




Andy Green (6):
      config: add js
      cgit.js: line range highlight: introduce javascript
      cgit.js: line range highlight: make responsive to url changes
      cgit.js: line range highlight: improve vertical scroll logic
      line-range-highlight: onclick handler and range selection
      line-range-highlight: copy URL to clipboard UI

 Makefile     |    1 
 cgit.c       |    3 +
 cgit.css     |   29 +++++++
 cgit.h       |    1 
 cgit.js      |  225 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 cgitrc.5.txt |    5 +
 ui-blame.c   |    2 -
 ui-shared.c  |    5 +
 ui-tree.c    |    2 -
 9 files changed, 271 insertions(+), 2 deletions(-)
 create mode 100644 cgit.js


More information about the CGit mailing list