@@ -89,6 +89,7 @@ class SearchcodeModel extends BaseModel {
8989 ( lineStr . match ( reg ) || [ ] ) . forEach ( val => {
9090 //remove "-" and "/" from the start and the end
9191 val = val . replace ( / ^ ( \- | \/ ) * / , '' ) . replace ( / ( \- | \/ ) * $ / , '' ) ;
92+ this . _updateVariableRepoMapping ( val , res ) ;
9293 if (
9394 ! / \/ / g. test ( val ) /*exclude links*/
9495 && vals . indexOf ( val ) === - 1
@@ -97,36 +98,45 @@ class SearchcodeModel extends BaseModel {
9798 && val . length < 64 /*too long*/
9899 ) {
99100 vals . push ( val ) ;
100- this . _updateVariableRepoMapping ( val , res ) ;
101101 //render variable labels
102102 variables . push ( {
103103 keyword : val ,
104104 repo : res ,
105- repoLen : this . _variableRepoMapping [ val ] . length ,
106105 color : Tools . randomLabelColor ( )
107106 } ) ;
108107 }
109108 } ) ;
110109 } ) ;
111110 } ) ;
112- return variables ;
111+ return variables . map ( val => {
112+ val . repoLen = this . _getVariableRepoMappingLength ( val . keyword ) ;
113+ return val ;
114+ } ) ;
113115 }
114116
115117 _parseSuggestion ( keywords , curr ) {
116118 let suggestion = curr || this . suggestion ;
117119 if ( keywords ) {
118120 suggestion = keywords . concat ( suggestion ) ;
119121 }
120- return [ ...new Set ( suggestion ) ] . filter ( ( item , i ) => ! this . _isZH ( item ) && i < 12 ) ;
122+ return [ ...new Set ( suggestion ) ] . filter ( ( item , i ) => ! this . _isZH ( item ) ) ;
121123 }
122124
123125 _updateVariableRepoMapping ( val , repo ) {
124- this . _variableRepoMapping [ val ] = this . _variableRepoMapping [ val ] || [ ] ;
125- if ( ! this . _variableRepoMapping [ val ] . find ( key => key . id === repo . id ) ) {
126- this . _variableRepoMapping [ val ] . push ( repo ) ;
126+ if ( ! / \/ / g. test ( val ) /*exclude links*/ && val . length < 64 /*too long*/ ) {
127+ val = `__${ val . toLowerCase ( ) } ` ;
128+ this . _variableRepoMapping [ val ] = this . _variableRepoMapping [ val ] || [ ] ;
129+ if ( ! this . _variableRepoMapping [ val ] . find ( key => key . id == repo . id ) ) {
130+ this . _variableRepoMapping [ val ] . push ( repo ) ;
131+ }
127132 }
128133 }
129134
135+ _getVariableRepoMappingLength ( val ) {
136+ val = `__${ val . toLowerCase ( ) } ` ;
137+ return this . _variableRepoMapping [ val ] . length ;
138+ }
139+
130140 _isZH ( val ) {
131141 let isZH = false ;
132142 val . replace ( / \s + / ig, '+' ) . split ( '+' ) . forEach ( ( key ) => {
0 commit comments