##// END OF EJS Templates
diffs: fixed selecting active lines in both types of diffs.
dan -
r3130:dc7450ba default
parent child Browse files
Show More
@@ -1132,6 +1132,9 b' table.cb {'
1132 1132 .icon-comment {
1133 1133 cursor: pointer;
1134 1134 }
1135 &.cb-line-selected {
1136 background: @comment-highlight-color !important;
1137 }
1135 1138 &.cb-line-selected > div {
1136 1139 display: block;
1137 1140 background: @comment-highlight-color !important;
@@ -1154,7 +1157,7 b' table.cb {'
1154 1157 a::before {
1155 1158 content: attr(data-line-no);
1156 1159 }
1157 &.cb-line-selected a {
1160 &.cb-line-selected {
1158 1161 background: @comment-highlight-color !important;
1159 1162 }
1160 1163
@@ -295,75 +295,81 b' function scrollToElement(element, percen'
295 295 });
296 296
297 297 $('body').on('click', '.cb-lineno a', function(event) {
298 function sortNumber(a,b) {
299 return a - b;
300 }
298 301
299 function sortNumber(a,b) {
300 return a - b;
302 var lineNo = $(this).data('lineNo');
303 var lineName = $(this).attr('name');
304
305 if (lineNo) {
306 var prevLine = $('.cb-line-selected a').data('lineNo');
307
308 // on shift, we do a range selection, if we got previous line
309 if (event.shiftKey && prevLine !== undefined) {
310 var prevLine = parseInt(prevLine);
311 var nextLine = parseInt(lineNo);
312 var pos = [prevLine, nextLine].sort(sortNumber);
313 var anchor = '#L{0}-{1}'.format(pos[0], pos[1]);
314
315 // single click
316 } else {
317 var nextLine = parseInt(lineNo);
318 var pos = [nextLine, nextLine];
319 var anchor = '#L{0}'.format(pos[0]);
320
321 }
322 // highlight
323 var range = [];
324 for (var i = pos[0]; i <= pos[1]; i++) {
325 range.push(i);
326 }
327 // clear old selected lines
328 $('.cb-line-selected').removeClass('cb-line-selected');
329
330 $.each(range, function (i, lineNo) {
331 var line_td = $('td.cb-lineno#L' + lineNo);
332
333 if (line_td.length) {
334 line_td.addClass('cb-line-selected'); // line number td
335 line_td.prev().addClass('cb-line-selected'); // line data
336 line_td.next().addClass('cb-line-selected'); // line content
337 }
338 });
339
340 } else if (lineName !== undefined) { // lineName only occurs in diffs
341 // clear old selected lines
342 $('td.cb-line-selected').removeClass('cb-line-selected');
343 var anchor = '#{0}'.format(lineName);
344 var diffmode = templateContext.session_attrs.diffmode || "sideside";
345
346 if (diffmode === "unified") {
347 $(this).closest('tr').find('td').addClass('cb-line-selected');
348 } else {
349 var activeTd = $(this).closest('td');
350 activeTd.addClass('cb-line-selected');
351 activeTd.next('td').addClass('cb-line-selected');
301 352 }
302 353
303 var lineNo = $(this).data('lineNo');
304 if (lineNo) {
305
306 // on shift, we do a range selection, if we got previous line
307 var prevLine = $('.cb-line-selected a').data('lineNo');
308 if (event.shiftKey && prevLine !== undefined) {
309 var prevLine = parseInt(prevLine);
310 var nextLine = parseInt(lineNo);
311 var pos = [prevLine, nextLine].sort(sortNumber);
312 var anchor = '#L{0}-{1}'.format(pos[0], pos[1]);
313
314 } else {
315
316 var nextLine = parseInt(lineNo);
317 var pos = [nextLine, nextLine];
318 var anchor = '#L{0}'.format(pos[0]);
354 }
319 355
320 }
321 // highlight
322 var range = [];
323 for (var i = pos[0]; i <= pos[1]; i++) {
324 range.push(i);
325 }
326 // clear selection
327 $('.cb-line-selected').removeClass('cb-line-selected');
328
329 $.each(range, function (i, lineNo) {
330 var line_td = $('td.cb-lineno#L' + lineNo);
331 if (line_td.length) {
332 line_td.addClass('cb-line-selected'); // line number td
333 line_td.prev().addClass('cb-line-selected'); // line data
334 line_td.next().addClass('cb-line-selected'); // line content
335 }
336 });
337
338
339 } else {
340 if ($(this).attr('name') !== undefined) {
341 // clear selection
342 $('td.cb-line-selected').removeClass('cb-line-selected');
343 var aEl = $(this).closest('td');
344 aEl.addClass('cb-line-selected');
345 aEl.next('td').addClass('cb-line-selected');
346 }
356 // Replace URL without jumping to it if browser supports.
357 // Default otherwise
358 if (history.pushState && anchor !== undefined) {
359 var new_location = location.href.rstrip('#');
360 if (location.hash) {
361 // location without hash
362 new_location = new_location.replace(location.hash, "");
347 363 }
348 364
349 // Replace URL without jumping to it if browser supports.
350 // Default otherwise
351 if (history.pushState && anchor !== undefined) {
352 var new_location = location.href.rstrip('#');
353 if (location.hash) {
354 // location without hash
355 new_location = new_location.replace(location.hash, "");
356 }
365 // Make new anchor url
366 new_location = new_location + anchor;
367 history.pushState(true, document.title, new_location);
357 368
358 // Make new anchor url
359 new_location = new_location + anchor;
360 history.pushState(true, document.title, new_location);
369 return false;
370 }
361 371
362 return false;
363 }
364
365 });
366
372 });
367 373
368 374 $('.collapse_file').on('click', function(e) {
369 375 e.stopPropagation();
General Comments 0
You need to be logged in to leave comments. Login now