@@ -256,21 +256,22 @@ coverage.pyfile_ready = function ($) {
256
256
257
257
coverage . init_scroll_markers ( ) ;
258
258
259
- // Rebuild scroll markers after window high changing
260
- $ ( window ) . resize ( coverage . resize_scroll_markers ) ;
259
+ // Rebuild scroll markers when the window height changes.
260
+ $ ( window ) . resize ( coverage . build_scroll_markers ) ;
261
261
} ;
262
262
263
263
coverage . toggle_lines = function ( btn , cls ) {
264
264
btn = $ ( btn ) ;
265
- var hide = "hide_ " + cls ;
266
- if ( btn . hasClass ( hide ) ) {
267
- $ ( "#source ." + cls ) . removeClass ( hide ) ;
268
- btn . removeClass ( hide ) ;
265
+ var show = "show_ " + cls ;
266
+ if ( btn . hasClass ( show ) ) {
267
+ $ ( "#source ." + cls ) . removeClass ( show ) ;
268
+ btn . removeClass ( show ) ;
269
269
}
270
270
else {
271
- $ ( "#source ." + cls ) . addClass ( hide ) ;
272
- btn . addClass ( hide ) ;
271
+ $ ( "#source ." + cls ) . addClass ( show ) ;
272
+ btn . addClass ( show ) ;
273
273
}
274
+ coverage . build_scroll_markers ( ) ;
274
275
} ;
275
276
276
277
// Return the nth line div.
@@ -283,11 +284,6 @@ coverage.num_elt = function (n) {
283
284
return $ ( "#n" + n ) ;
284
285
} ;
285
286
286
- // Return the container of all the code.
287
- coverage . code_container = function ( ) {
288
- return $ ( ".linenos" ) ;
289
- } ;
290
-
291
287
// Set the selection. b and e are line numbers.
292
288
coverage . set_sel = function ( b , e ) {
293
289
// The first line selected.
@@ -306,24 +302,32 @@ coverage.to_first_chunk = function () {
306
302
coverage . to_next_chunk ( ) ;
307
303
} ;
308
304
309
- coverage . is_transparent = function ( color ) {
310
- // Different browsers return different colors for "none".
311
- return color === "transparent" || color === "rgba(0, 0, 0, 0)" ;
305
+ // Return a string indicating what kind of chunk this line belongs to,
306
+ // or null if not a chunk.
307
+ coverage . chunk_indicator = function ( line_elt ) {
308
+ var klass = line_elt . attr ( 'class' ) ;
309
+ if ( klass ) {
310
+ var m = klass . match ( / \b s h o w _ \w + \b / ) ;
311
+ if ( m ) {
312
+ return m [ 0 ] ;
313
+ }
314
+ }
315
+ return null ;
312
316
} ;
313
317
314
318
coverage . to_next_chunk = function ( ) {
315
319
var c = coverage ;
316
320
317
321
// Find the start of the next colored chunk.
318
322
var probe = c . sel_end ;
319
- var color , probe_line ;
323
+ var chunk_indicator , probe_line ;
320
324
while ( true ) {
321
325
probe_line = c . line_elt ( probe ) ;
322
326
if ( probe_line . length === 0 ) {
323
327
return ;
324
328
}
325
- color = probe_line . css ( "background-color" ) ;
326
- if ( ! c . is_transparent ( color ) ) {
329
+ chunk_indicator = c . chunk_indicator ( probe_line ) ;
330
+ if ( chunk_indicator ) {
327
331
break ;
328
332
}
329
333
probe ++ ;
@@ -333,11 +337,11 @@ coverage.to_next_chunk = function () {
333
337
var begin = probe ;
334
338
335
339
// Find the end of this chunk.
336
- var next_color = color ;
337
- while ( next_color === color ) {
340
+ var next_indicator = chunk_indicator ;
341
+ while ( next_indicator === chunk_indicator ) {
338
342
probe ++ ;
339
343
probe_line = c . line_elt ( probe ) ;
340
- next_color = probe_line . css ( "background-color" ) ;
344
+ next_indicator = c . chunk_indicator ( probe_line ) ;
341
345
}
342
346
c . set_sel ( begin , probe ) ;
343
347
c . show_selection ( ) ;
@@ -352,25 +356,25 @@ coverage.to_prev_chunk = function () {
352
356
if ( probe_line . length === 0 ) {
353
357
return ;
354
358
}
355
- var color = probe_line . css ( "background-color" ) ;
356
- while ( probe > 0 && c . is_transparent ( color ) ) {
359
+ var chunk_indicator = c . chunk_indicator ( probe_line ) ;
360
+ while ( probe > 0 && ! chunk_indicator ) {
357
361
probe -- ;
358
362
probe_line = c . line_elt ( probe ) ;
359
363
if ( probe_line . length === 0 ) {
360
364
return ;
361
365
}
362
- color = probe_line . css ( "background-color" ) ;
366
+ chunk_indicator = c . chunk_indicator ( probe_line ) ;
363
367
}
364
368
365
369
// There's a prev chunk, `probe` points to its last line.
366
370
var end = probe + 1 ;
367
371
368
372
// Find the beginning of this chunk.
369
- var prev_color = color ;
370
- while ( prev_color === color ) {
373
+ var prev_indicator = chunk_indicator ;
374
+ while ( prev_indicator === chunk_indicator ) {
371
375
probe -- ;
372
376
probe_line = c . line_elt ( probe ) ;
373
- prev_color = probe_line . css ( "background-color" ) ;
377
+ prev_indicator = c . chunk_indicator ( probe_line ) ;
374
378
}
375
379
c . set_sel ( probe + 1 , end ) ;
376
380
c . show_selection ( ) ;
@@ -442,29 +446,29 @@ coverage.select_line_or_chunk = function (lineno) {
442
446
if ( probe_line . length === 0 ) {
443
447
return ;
444
448
}
445
- var the_color = probe_line . css ( "background-color" ) ;
446
- if ( ! c . is_transparent ( the_color ) ) {
449
+ var the_indicator = c . chunk_indicator ( probe_line ) ;
450
+ if ( the_indicator ) {
447
451
// The line is in a highlighted chunk.
448
452
// Search backward for the first line.
449
453
var probe = lineno ;
450
- var color = the_color ;
451
- while ( probe > 0 && color === the_color ) {
454
+ var indicator = the_indicator ;
455
+ while ( probe > 0 && indicator === the_indicator ) {
452
456
probe -- ;
453
457
probe_line = c . line_elt ( probe ) ;
454
458
if ( probe_line . length === 0 ) {
455
459
break ;
456
460
}
457
- color = probe_line . css ( "background-color" ) ;
461
+ indicator = c . chunk_indicator ( probe_line ) ;
458
462
}
459
463
var begin = probe + 1 ;
460
464
461
465
// Search forward for the last line.
462
466
probe = lineno ;
463
- color = the_color ;
464
- while ( color === the_color ) {
467
+ indicator = the_indicator ;
468
+ while ( indicator === the_indicator ) {
465
469
probe ++ ;
466
470
probe_line = c . line_elt ( probe ) ;
467
- color = probe_line . css ( "background-color" ) ;
471
+ indicator = c . chunk_indicator ( probe_line ) ;
468
472
}
469
473
470
474
coverage . set_sel ( begin , probe ) ;
@@ -478,7 +482,7 @@ coverage.show_selection = function () {
478
482
var c = coverage ;
479
483
480
484
// Highlight the lines in the chunk
481
- c . code_container ( ) . find ( " .highlight") . removeClass ( "highlight" ) ;
485
+ $ ( ".linenos .highlight") . removeClass ( "highlight" ) ;
482
486
for ( var probe = c . sel_begin ; probe > 0 && probe < c . sel_end ; probe ++ ) {
483
487
c . num_elt ( probe ) . addClass ( "highlight" ) ;
484
488
}
@@ -511,18 +515,18 @@ coverage.init_scroll_markers = function () {
511
515
c . lines_len = $ ( 'td.text p' ) . length ;
512
516
c . body_h = $ ( 'body' ) . height ( ) ;
513
517
c . header_h = $ ( 'div#header' ) . height ( ) ;
514
- c . missed_lines = $ ( 'td.text p.mis, td.text p.par' ) ;
515
518
516
519
// Build html
517
- c . resize_scroll_markers ( ) ;
520
+ c . build_scroll_markers ( ) ;
518
521
} ;
519
522
520
- coverage . resize_scroll_markers = function ( ) {
523
+ coverage . build_scroll_markers = function ( ) {
521
524
var c = coverage ,
522
525
min_line_height = 3 ,
523
526
max_line_height = 10 ,
524
527
visible_window_h = $ ( window ) . height ( ) ;
525
528
529
+ c . lines_to_mark = $ ( 'td.text' ) . find ( 'p.show_run, p.show_mis, p.show_exc, p.show_par' ) ;
526
530
$ ( '#scroll_marker' ) . remove ( ) ;
527
531
// Don't build markers if the window has no scroll bar.
528
532
if ( c . body_h <= visible_window_h ) {
@@ -550,10 +554,10 @@ coverage.resize_scroll_markers = function () {
550
554
offsets = { } ;
551
555
552
556
// Calculate line offsets outside loop to prevent relayouts
553
- c . missed_lines . each ( function ( ) {
557
+ c . lines_to_mark . each ( function ( ) {
554
558
offsets [ this . id ] = $ ( this ) . offset ( ) . top ;
555
559
} ) ;
556
- c . missed_lines . each ( function ( ) {
560
+ c . lines_to_mark . each ( function ( ) {
557
561
var id_name = $ ( this ) . attr ( 'id' ) ,
558
562
line_top = Math . round ( offsets [ id_name ] * marker_scale ) ,
559
563
line_number = parseInt ( id_name . substring ( 1 , id_name . length ) ) ;
0 commit comments