##// END OF EJS Templates
files-source: allow making a range selection with shift on file lines.
ergo -
r2483:aae8d716 default
parent child Browse files
Show More
@@ -315,23 +315,54 b' function scrollToElement(element, percen'
315 315 when new diffs are integrated */
316 316 'click', '.cb-lineno a', function(event) {
317 317
318 function sortNumber(a,b) {
319 return a - b;
320 }
321
318 322 if ($(this).attr('data-line-no') !== ""){
323
324 // on shift, we do a range selection, if we got previous line
325 var prevLine = $('.cb-line-selected a').attr('data-line-no');
326 if (event.shiftKey && prevLine !== undefined) {
327 var prevLine = parseInt(prevLine);
328 var nextLine = parseInt($(this).attr('data-line-no'));
329 var pos = [prevLine, nextLine].sort(sortNumber);
330 var anchor = '#L{0}-{1}'.format(pos[0], pos[1]);
331
332 } else {
333 var nextLine = parseInt($(this).attr('data-line-no'));
334 var pos = [nextLine, nextLine];
335 var anchor = '#L{0}'.format(pos[0]);
336
337 }
338 // highlight
339 var range = [];
340 for (var i = pos[0]; i <= pos[1]; i++) {
341 range.push(i);
342 }
343 // clear selection
319 344 $('.cb-line-selected').removeClass('cb-line-selected');
320 var td = $(this).parent();
321 td.addClass('cb-line-selected'); // line number td
322 td.prev().addClass('cb-line-selected'); // line data td
323 td.next().addClass('cb-line-selected'); // line content td
345
346 $.each(range, function (i, lineNo) {
347 var line_td = $('td.cb-lineno#L' + lineNo);
348 if (line_td.length) {
349 line_td.addClass('cb-line-selected'); // line number td
350 line_td.prev().addClass('cb-line-selected'); // line data
351 line_td.next().addClass('cb-line-selected'); // line content
352 }
353 });
324 354
325 355 // Replace URL without jumping to it if browser supports.
326 356 // Default otherwise
327 357 if (history.pushState) {
328 358 var new_location = location.href.rstrip('#');
329 359 if (location.hash) {
360 // location without hash
330 361 new_location = new_location.replace(location.hash, "");
331 362 }
332 363
333 364 // Make new anchor url
334 new_location = new_location + $(this).attr('href');
365 new_location = new_location + anchor;
335 366 history.pushState(true, document.title, new_location);
336 367
337 368 return false;
General Comments 0
You need to be logged in to leave comments. Login now