@@ -14,7 +14,7 @@ function changeHash(hash: string) {
14
14
// it selects the code lines defined by range: `L1-L3` (3 lines) or `L2` (singe line)
15
15
function selectRange ( range : string ) : Element {
16
16
for ( const el of document . querySelectorAll ( '.code-view tr.active' ) ) el . classList . remove ( 'active' ) ;
17
- const elLineNums = document . querySelectorAll ( `.code-view td.lines-num span[data-line-number ]` ) ;
17
+ const elLineNums = document . querySelectorAll ( `.code-view td.lines-num[id^="L" ]` ) ;
18
18
19
19
const refInNewIssue = document . querySelector ( 'a.ref-in-new-issue' ) ;
20
20
const copyPermalink = document . querySelector ( 'a.copy-line-permalink' ) ;
@@ -81,11 +81,12 @@ function showLineButton() {
81
81
el . remove ( ) ;
82
82
}
83
83
84
- // find active row and add button
85
- const tr = document . querySelector ( '.code-view tr.active' ) ;
86
- if ( ! tr ) return ;
84
+ // Find first active row and add button
85
+ const activeRows = document . querySelectorAll ( '.code-view tr.active' ) ;
86
+ if ( activeRows . length === 0 ) return ;
87
87
88
- const td = tr . querySelector ( 'td.lines-num' ) ;
88
+ const firstActiveRow = activeRows [ 0 ] ;
89
+ const td = firstActiveRow . querySelector ( 'td.lines-num' ) ;
89
90
const btn = document . createElement ( 'button' ) ;
90
91
btn . classList . add ( 'code-line-button' , 'ui' , 'basic' , 'button' ) ;
91
92
btn . innerHTML = svg ( 'octicon-kebab-horizontal' ) ;
@@ -96,16 +97,30 @@ function showLineButton() {
96
97
97
98
createTippy ( btn , {
98
99
theme : 'menu' ,
99
- trigger : 'click' ,
100
- hideOnClick : true ,
100
+ trigger : 'manual' , // Use manual trigger
101
101
content : menu ,
102
102
placement : 'right-start' ,
103
103
interactive : true ,
104
- onShow : ( tippy ) => {
105
- tippy . popper . addEventListener ( 'click' , ( ) => {
106
- tippy . hide ( ) ;
107
- } , { once : true } ) ;
108
- } ,
104
+ appendTo : ( ) => document . body ,
105
+ } ) ;
106
+
107
+ // Handle menu button click manually
108
+ btn . addEventListener ( 'click' , ( e ) => {
109
+ e . stopPropagation ( ) ;
110
+ const tippyInstance = btn . _tippy ;
111
+ if ( tippyInstance && tippyInstance . state . isVisible ) {
112
+ tippyInstance . hide ( ) ;
113
+ } else if ( tippyInstance ) {
114
+ tippyInstance . show ( ) ;
115
+ }
116
+ } ) ;
117
+
118
+ // Hide menu when clicking menu items
119
+ menu . addEventListener ( 'click' , ( ) => {
120
+ const tippyInstance = btn . _tippy ;
121
+ if ( tippyInstance ) {
122
+ tippyInstance . hide ( ) ;
123
+ }
109
124
} ) ;
110
125
}
111
126
@@ -118,7 +133,7 @@ export function initRepoCodeView() {
118
133
119
134
// "file code view" and "blame" pages need this "line number button" feature
120
135
let selRangeStart : string ;
121
- addDelegatedEventListener ( document , 'click' , '.code-view .lines-num span ' , ( el : HTMLElement , e : KeyboardEvent ) => {
136
+ addDelegatedEventListener ( document , 'click' , '.code-view .lines-num' , ( el : HTMLElement , e : KeyboardEvent ) => {
122
137
if ( ! selRangeStart || ! e . shiftKey ) {
123
138
selRangeStart = el . getAttribute ( 'id' ) ;
124
139
selectRange ( selRangeStart ) ;
0 commit comments