@@ -2,7 +2,6 @@ import {svg} from '../svg.ts';
22import { createTippy } from '../modules/tippy.ts' ;
33import { toAbsoluteUrl } from '../utils.ts' ;
44import { addDelegatedEventListener } from '../utils/dom.ts' ;
5- import { registerGlobalInitFunc } from '../modules/observer.ts' ;
65
76function changeHash ( hash : string ) {
87 if ( window . history . pushState ) {
@@ -111,25 +110,26 @@ function showLineButton() {
111110}
112111
113112export function initRepoCodeView ( ) {
114- registerGlobalInitFunc ( 'initRepoCodeView' , ( el : HTMLElement ) => {
115- if ( ! el . querySelector ( '.lines-num' ) ) return ;
116-
117- let selRangeStart : string ;
118- addDelegatedEventListener ( el , 'click' , '.lines-num span' , ( el : HTMLElement , e : KeyboardEvent ) => {
119- if ( ! selRangeStart || ! e . shiftKey ) {
120- selRangeStart = el . getAttribute ( 'id' ) ;
121- selectRange ( selRangeStart ) ;
122- } else {
123- const selRangeStop = el . getAttribute ( 'id' ) ;
124- selectRange ( `${ selRangeStart } -${ selRangeStop } ` ) ;
125- }
126- window . getSelection ( ) . removeAllRanges ( ) ;
127- showLineButton ( ) ;
128- } ) ;
113+ if ( ! document . querySelector ( '.file-view.code-view' ) ) return ;
114+
115+ // "file code view" and "blame" pages need this "line number button" feature
116+ let selRangeStart : string ;
117+ addDelegatedEventListener ( document , 'click' , '.code-view .lines-num span' , ( el : HTMLElement , e : KeyboardEvent ) => {
118+ if ( ! selRangeStart || ! e . shiftKey ) {
119+ selRangeStart = el . getAttribute ( 'id' ) ;
120+ selectRange ( selRangeStart ) ;
121+ } else {
122+ const selRangeStop = el . getAttribute ( 'id' ) ;
123+ selectRange ( `${ selRangeStart } -${ selRangeStop } ` ) ;
124+ }
125+ window . getSelection ( ) . removeAllRanges ( ) ;
126+ showLineButton ( ) ;
129127 } ) ;
130128
129+ // apply the selected range from the URL hash
131130 const onHashChange = ( ) => {
132131 if ( ! window . location . hash ) return ;
132+ if ( ! document . querySelector ( '.code-view .lines-num' ) ) return ;
133133 const range = window . location . hash . substring ( 1 ) ;
134134 const first = selectRange ( range ) ;
135135 if ( first ) {
0 commit comments