@@ -2475,12 +2475,11 @@ fn render_call_locations(w: &mut Buffer, cx: &Context<'_>, def_id: DefId, item:
24752475 } ;
24762476
24772477 // Generate a unique ID so users can link to this section for a given method
2478- // FIXME: this should use init_id_map instead of derive
24792478 let id = cx. id_map . borrow_mut ( ) . derive ( "scraped-examples" ) ;
24802479 write ! (
24812480 w,
24822481 "<div class=\" docblock scraped-example-list\" >\
2483- <span></span>
2482+ <span></span>\
24842483 <h5 id=\" {id}\" class=\" section-header\" >\
24852484 <a href=\" #{id}\" >Examples found in repository</a>\
24862485 </h5>",
@@ -2516,42 +2515,51 @@ fn render_call_locations(w: &mut Buffer, cx: &Context<'_>, def_id: DefId, item:
25162515
25172516 // The call locations need to be updated to reflect that the size of the program has changed.
25182517 // Specifically, the ranges are all subtracted by `byte_min` since that's the new zero point.
2519- let ( byte_ranges, line_ranges) : ( Vec < _ > , Vec < _ > ) = call_data
2518+ let ( mut byte_ranges, line_ranges) : ( Vec < _ > , Vec < _ > ) = call_data
25202519 . locations
25212520 . iter ( )
25222521 . map ( |loc| {
25232522 let ( byte_lo, byte_hi) = loc. call_expr . byte_span ;
25242523 let ( line_lo, line_hi) = loc. call_expr . line_span ;
2525- ( ( byte_lo - byte_min, byte_hi - byte_min) , ( line_lo - line_min, line_hi - line_min) )
2524+ let byte_range = ( byte_lo - byte_min, byte_hi - byte_min) ;
2525+ let line_range = ( line_lo - line_min, line_hi - line_min) ;
2526+ let ( anchor, line_title) = if line_lo == line_hi {
2527+ ( format ! ( "{}" , line_lo + 1 ) , format ! ( "line {}" , line_lo + 1 ) )
2528+ } else {
2529+ (
2530+ format ! ( "{}-{}" , line_lo + 1 , line_hi + 1 ) ,
2531+ format ! ( "lines {}-{}" , line_lo + 1 , line_hi + 1 ) ,
2532+ )
2533+ } ;
2534+ let line_url = format ! ( "{}{}#{}" , cx. root_path( ) , call_data. url, anchor) ;
2535+
2536+ ( byte_range, ( line_range, line_url, line_title) )
25262537 } )
25272538 . unzip ( ) ;
25282539
2529- let ( init_min, init_max) = line_ranges[ 0 ] ;
2530- let line_range = if init_min == init_max {
2531- format ! ( "line {}" , init_min + line_min + 1 )
2532- } else {
2533- format ! ( "lines {}-{}" , init_min + line_min + 1 , init_max + line_min + 1 )
2534- } ;
2535-
2540+ let ( _, init_url, init_title) = & line_ranges[ 0 ] ;
25362541 let needs_expansion = line_max - line_min > NUM_VISIBLE_LINES ;
2542+ let locations_encoded = serde_json:: to_string ( & line_ranges) . unwrap ( ) ;
25372543
25382544 write ! (
25392545 w,
25402546 "<div class=\" scraped-example {expanded_cls}\" data-locs=\" {locations}\" >\
25412547 <div class=\" scraped-example-title\" >\
2542- {name} (<a href=\" {root}{ url}\" >{line_range }</a>)\
2548+ {name} (<a href=\" {url}\" >{title }</a>)\
25432549 </div>\
25442550 <div class=\" code-wrapper\" >",
2545- root = cx. root_path( ) ,
2546- url = call_data. url,
2547- name = call_data. display_name,
2548- line_range = line_range,
25492551 expanded_cls = if needs_expansion { "" } else { "expanded" } ,
2552+ name = call_data. display_name,
2553+ url = init_url,
2554+ title = init_title,
25502555 // The locations are encoded as a data attribute, so they can be read
25512556 // later by the JS for interactions.
2552- locations = serde_json :: to_string ( & line_ranges ) . unwrap ( ) ,
2557+ locations = Escape ( & locations_encoded )
25532558 ) ;
2554- write ! ( w, r#"<span class="prev">≺</span> <span class="next">≻</span>"# ) ;
2559+
2560+ if line_ranges. len ( ) > 1 {
2561+ write ! ( w, r#"<span class="prev">≺</span> <span class="next">≻</span>"# ) ;
2562+ }
25552563
25562564 if needs_expansion {
25572565 write ! ( w, r#"<span class="expand">↕</span>"# ) ;
@@ -2580,6 +2588,7 @@ fn render_call_locations(w: &mut Buffer, cx: &Context<'_>, def_id: DefId, item:
25802588 let root_path = vec ! [ "../" ; cx. current. len( ) - 1 ] . join ( "" ) ;
25812589
25822590 let mut decoration_info = FxHashMap :: default ( ) ;
2591+ decoration_info. insert ( "highlight focus" , vec ! [ byte_ranges. remove( 0 ) ] ) ;
25832592 decoration_info. insert ( "highlight" , byte_ranges) ;
25842593
25852594 sources:: print_src (
0 commit comments