@@ -2917,6 +2917,27 @@ function deSelect() {
29172917
29182918function selectRange ( $list , $select , $from ) {
29192919 $list . removeClass ( 'active' ) ;
2920+
2921+ // add hashchange to permalink
2922+ const $issue = $ ( 'a.ref-in-new-issue' ) ;
2923+ const $copyPermalink = $ ( 'a.copy-line-permalink' ) ;
2924+
2925+ if ( $issue . length === 0 || $copyPermalink . length === 0 ) {
2926+ return ;
2927+ }
2928+
2929+ const updateIssueHref = function ( anchor ) {
2930+ let href = $issue . attr ( 'href' ) ;
2931+ href = `${ href . replace ( / % 2 3 L \d + $ | % 2 3 L \d + - L \d + $ / , '' ) } %23${ anchor } ` ;
2932+ $issue . attr ( 'href' , href ) ;
2933+ } ;
2934+
2935+ const updateCopyPermalinkHref = function ( anchor ) {
2936+ let link = $copyPermalink . attr ( 'data-clipboard-text' ) ;
2937+ link = `${ link . replace ( / # L \d + $ | # L \d + - L \d + $ / , '' ) } #${ anchor } ` ;
2938+ $copyPermalink . attr ( 'data-clipboard-text' , link ) ;
2939+ } ;
2940+
29202941 if ( $from ) {
29212942 let a = parseInt ( $select . attr ( 'rel' ) . substr ( 1 ) ) ;
29222943 let b = parseInt ( $from . attr ( 'rel' ) . substr ( 1 ) ) ;
@@ -2934,38 +2955,16 @@ function selectRange($list, $select, $from) {
29342955 $list . filter ( classes . join ( ',' ) ) . addClass ( 'active' ) ;
29352956 changeHash ( `#L${ a } -L${ b } ` ) ;
29362957
2937- // add hashchange to permalink
2938- const $issue = $ ( 'a.ref-in-new-issue' ) ;
2939-
2940- if ( $issue . length === 0 ) {
2941- return ;
2942- }
2943-
2944- const matched = $issue . attr ( 'href' ) . match ( / % 2 3 L \d + $ | % 2 3 L \d + - L \d + $ / ) ;
2945- if ( matched ) {
2946- $issue . attr ( 'href' , $issue . attr ( 'href' ) . replace ( $issue . attr ( 'href' ) . substr ( matched . index ) , `%23L${ a } -L${ b } ` ) ) ;
2947- } else {
2948- $issue . attr ( 'href' , `${ $issue . attr ( 'href' ) } %23L${ a } -L${ b } ` ) ;
2949- }
2958+ updateIssueHref ( `L${ a } -L${ b } ` ) ;
2959+ updateCopyPermalinkHref ( `L${ a } -L${ b } ` ) ;
29502960 return ;
29512961 }
29522962 }
29532963 $select . addClass ( 'active' ) ;
29542964 changeHash ( `#${ $select . attr ( 'rel' ) } ` ) ;
29552965
2956- // add hashchange to permalink
2957- const $issue = $ ( 'a.ref-in-new-issue' ) ;
2958-
2959- if ( $issue . length === 0 ) {
2960- return ;
2961- }
2962-
2963- const matched = $issue . attr ( 'href' ) . match ( / % 2 3 L \d + $ | % 2 3 L \d + - L \d + $ / ) ;
2964- if ( matched ) {
2965- $issue . attr ( 'href' , $issue . attr ( 'href' ) . replace ( $issue . attr ( 'href' ) . substr ( matched . index ) , `%23${ $select . attr ( 'rel' ) } ` ) ) ;
2966- } else {
2967- $issue . attr ( 'href' , `${ $issue . attr ( 'href' ) } %23${ $select . attr ( 'rel' ) } ` ) ;
2968- }
2966+ updateIssueHref ( $select . attr ( 'rel' ) ) ;
2967+ updateCopyPermalinkHref ( $select . attr ( 'rel' ) ) ;
29692968}
29702969
29712970$ ( ( ) => {
0 commit comments