@@ -2,6 +2,9 @@ import $ from 'jquery';
2
2
import { svg } from '../svg.js' ;
3
3
import { invertFileFolding } from './file-fold.js' ;
4
4
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
+
5
8
function changeHash ( hash ) {
6
9
if ( window . history . pushState ) {
7
10
window . history . pushState ( null , null , hash ) ;
@@ -114,7 +117,7 @@ export function initRepoCodeView() {
114
117
} ) ;
115
118
116
119
$ ( window ) . on ( 'hashchange' , ( ) => {
117
- let m = window . location . hash . match ( / ^ # ( L \d + ) - ( L \d + ) $ / ) ;
120
+ let m = window . location . hash . match ( rangeAnchorRegex ) ;
118
121
let $list ;
119
122
if ( $ ( 'div.blame' ) . length ) {
120
123
$list = $ ( '.code-view td.lines-code.blame-code' ) ;
@@ -124,27 +127,31 @@ export function initRepoCodeView() {
124
127
let $first ;
125
128
if ( m ) {
126
129
$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 ] } ]` ) ) ;
128
132
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
+ }
133
137
134
- $ ( 'html, body' ) . scrollTop ( $first . offset ( ) . top - 200 ) ;
135
- return ;
138
+ $ ( 'html, body' ) . scrollTop ( $first . offset ( ) . top - 200 ) ;
139
+ return ;
140
+ }
136
141
}
137
- m = window . location . hash . match ( / ^ # ( L | n ) ( \d + ) $ / ) ;
142
+ m = window . location . hash . match ( singleAnchorRegex ) ;
138
143
if ( m ) {
139
144
$first = $list . filter ( `[rel=L${ m [ 2 ] } ]` ) ;
140
- selectRange ( $list , $first ) ;
145
+ if ( $first . length ) {
146
+ selectRange ( $list , $first ) ;
141
147
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
+ }
146
152
147
- $ ( 'html, body' ) . scrollTop ( $first . offset ( ) . top - 200 ) ;
153
+ $ ( 'html, body' ) . scrollTop ( $first . offset ( ) . top - 200 ) ;
154
+ }
148
155
}
149
156
} ) . trigger ( 'hashchange' ) ;
150
157
}
0 commit comments