@@ -2,6 +2,9 @@ import $ from 'jquery';
22import { svg } from '../svg.js' ;
33import { invertFileFolding } from './file-fold.js' ;
44
5+ export const singleAnchorRegex = / ^ # ( L | n ) ( [ 1 - 9 ] [ 0 - 9 ] * ) $ / ;
6+ export const rangeAnchorRegex = / ^ # ( L [ 1 - 9 ] [ 0 - 9 ] * ) - ( L [ 1 - 9 ] [ 0 - 9 ] * ) $ / ;
7+
58function changeHash ( hash ) {
69 if ( window . history . pushState ) {
710 window . history . pushState ( null , null , hash ) ;
@@ -114,7 +117,7 @@ export function initRepoCodeView() {
114117 } ) ;
115118
116119 $ ( window ) . on ( 'hashchange' , ( ) => {
117- let m = window . location . hash . match ( / ^ # ( L \d + ) - ( L \d + ) $ / ) ;
120+ let m = window . location . hash . match ( rangeAnchorRegex ) ;
118121 let $list ;
119122 if ( $ ( 'div.blame' ) . length ) {
120123 $list = $ ( '.code-view td.lines-code.blame-code' ) ;
@@ -124,27 +127,31 @@ export function initRepoCodeView() {
124127 let $first ;
125128 if ( m ) {
126129 $first = $list . filter ( `[rel=${ m [ 1 ] } ]` ) ;
127- selectRange ( $list , $first , $list . filter ( `[rel=${ m [ 2 ] } ]` ) ) ;
130+ if ( $first . length ) {
131+ selectRange ( $list , $first , $list . filter ( `[rel=${ m [ 2 ] } ]` ) ) ;
128132
129- // show code view menu marker (don't show in blame page)
130- if ( $ ( 'div.blame' ) . length === 0 ) {
131- showLineButton ( ) ;
132- }
133+ // show code view menu marker (don't show in blame page)
134+ if ( $ ( 'div.blame' ) . length === 0 ) {
135+ showLineButton ( ) ;
136+ }
133137
134- $ ( 'html, body' ) . scrollTop ( $first . offset ( ) . top - 200 ) ;
135- return ;
138+ $ ( 'html, body' ) . scrollTop ( $first . offset ( ) . top - 200 ) ;
139+ return ;
140+ }
136141 }
137- m = window . location . hash . match ( / ^ # ( L | n ) ( \d + ) $ / ) ;
142+ m = window . location . hash . match ( singleAnchorRegex ) ;
138143 if ( m ) {
139144 $first = $list . filter ( `[rel=L${ m [ 2 ] } ]` ) ;
140- selectRange ( $list , $first ) ;
145+ if ( $first . length ) {
146+ selectRange ( $list , $first ) ;
141147
142- // show code view menu marker (don't show in blame page)
143- if ( $ ( 'div.blame' ) . length === 0 ) {
144- showLineButton ( ) ;
145- }
148+ // show code view menu marker (don't show in blame page)
149+ if ( $ ( 'div.blame' ) . length === 0 ) {
150+ showLineButton ( ) ;
151+ }
146152
147- $ ( 'html, body' ) . scrollTop ( $first . offset ( ) . top - 200 ) ;
153+ $ ( 'html, body' ) . scrollTop ( $first . offset ( ) . top - 200 ) ;
154+ }
148155 }
149156 } ) . trigger ( 'hashchange' ) ;
150157 }
0 commit comments