File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed
Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -8,20 +8,31 @@ export default class Root extends Directory {
88 // FIXME: exists altanarive way?
99 const baseUrl = document . querySelector ( 'header.main-header a.logo' ) . getAttribute ( 'href' ) ;
1010 const relPath = document . location . pathname . replace ( baseUrl , '' ) ;
11+ let rootPath ;
12+ let branch ;
13+ if ( [ 'tree' , 'blob' ] . some ( s => relPath . includes ( `/${ s } /` ) ) ) {
14+ const m = relPath . match ( / ( ^ \/ ? [ ^ / ] + \/ [ ^ / ] + ) \/ (?: t r e e | b l o b ) \/ ( [ ^ / ] + ) / ) ;
15+ rootPath = m [ 1 ] ;
16+ branch = m [ 2 ] ;
17+ } else {
18+ rootPath = relPath . match ( / ^ \/ ? [ ^ / ] + \/ [ ^ / ] + / ) ;
19+ branch = '' ;
20+ }
1121 this . setState ( {
12- rootPath : `${ baseUrl } ${ relPath . match ( / ^ \/ ? [ ^ / ] + \/ [ ^ / ] + / ) } ` ,
22+ rootPath : `${ baseUrl } ${ rootPath } ` ,
23+ branch,
1324 } ) ;
1425 }
1526
1627 getLocalStorageKey ( ) {
17- return this . state . rootPath ;
28+ return ` ${ this . state . rootPath } / ${ this . state . branch } ` ;
1829 }
1930
2031 render ( ) {
2132 const arrow = this . state . expanded ? 'octicon octicon-chevron-down' : 'octicon octicon-chevron-right' ;
2233 return (
2334 < div className = "tree-node" >
24- < button className = "root-expander" onClick = { ( ) => this . toggleFolder ( `${ this . state . rootPath } /explore/` ) } >
35+ < button className = "root-expander" onClick = { ( ) => this . toggleFolder ( `${ this . state . rootPath } /explore/${ this . state . branch } ` ) } >
2536 < i className = { arrow } />
2637 </ button >
2738 < a href = { this . state . rootPath } className = "submenu-files" >
You can’t perform that action at this time.
0 commit comments