File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -1304,6 +1304,36 @@ export class CodeSnippetDisplay extends React.Component<
13041304 return null ;
13051305 }
13061306
1307+ // This function will be called to process user input for a narrowed search
1308+ // using various options. The user will enter a single search term which will
1309+ // searched across multiple options (name, lang, code).
1310+ filterSnippetsHelper = ( searchValue : string , options : string [ ] ) => {
1311+ const matchResults : StringExt . IMatchResult [ ] = [ ] ;
1312+ const filteredSnippets = this . props . codeSnippets ;
1313+ //let language: boolean = false;
1314+ //let code: boolean = false;
1315+ const filteredSnippetsScore : {
1316+ score : number ;
1317+ snippet : ICodeSnippet ;
1318+ } [ ] = [ ] ;
1319+ if ( searchValue !== '' ) {
1320+ filteredSnippets . forEach ( snippet => {
1321+ const matchResult = StringExt . matchSumOfSquares (
1322+ ( snippet . language + snippet . name ) . toLowerCase ( ) ,
1323+ searchValue . replace ( ' ' , '' ) . toLowerCase ( )
1324+ ) ;
1325+
1326+ if ( matchResult ) {
1327+ matchResults . push ( matchResult ) ;
1328+ filteredSnippetsScore . push ( {
1329+ score : matchResult . score ,
1330+ snippet : snippet
1331+ } ) ;
1332+ }
1333+ } ) ;
1334+ }
1335+ } ;
1336+
13071337 filterSnippets = ( searchValue : string , filterTags : string [ ] ) : void => {
13081338 // filter with search
13091339 let matchIndices : number [ ] [ ] = [ ] ;
You can’t perform that action at this time.
0 commit comments