@@ -1334,7 +1334,11 @@ export class CodeSnippetDisplay extends React.Component<
13341334 }
13351335 } ;
13361336
1337- filterSnippets = ( searchValue : string , filterTags : string [ ] ) : void => {
1337+ filterSnippets = (
1338+ searchValue : string ,
1339+ filterTags : string [ ] ,
1340+ languageTags : string [ ]
1341+ ) : void => {
13381342 // filter with search
13391343 let matchIndices : number [ ] [ ] = [ ] ;
13401344 const matchResults : StringExt . IMatchResult [ ] = [ ] ;
@@ -1435,7 +1439,11 @@ export class CodeSnippetDisplay extends React.Component<
14351439 } else {
14361440 filteredSnippets . forEach ( snippet => {
14371441 const matchResult = StringExt . matchSumOfSquares (
1438- ( snippet . language + snippet . name ) . toLowerCase ( ) ,
1442+ (
1443+ snippet . language +
1444+ snippet . name +
1445+ snippet . code . join ( '\n' )
1446+ ) . toLowerCase ( ) ,
14391447 searchValue . replace ( ' ' , '' ) . toLowerCase ( )
14401448 ) ;
14411449
@@ -1462,13 +1470,17 @@ export class CodeSnippetDisplay extends React.Component<
14621470 matchResults . forEach ( res => matchIndices . push ( res . indices ) ) ;
14631471 }
14641472
1465- // filter with tags
1473+ // filter with tags --- create a helper function with this code and call on both tags & languages
1474+ // 2 if statements filter by cell tags then language tags
14661475 if ( filterTags . length !== 0 ) {
14671476 const newMatchIndices = matchIndices . slice ( ) ;
14681477 filteredSnippets = filteredSnippets . filter ( ( codeSnippet , id ) => {
14691478 return filterTags . some ( tag => {
14701479 if ( codeSnippet . tags ) {
1471- if ( codeSnippet . tags . includes ( tag ) ) {
1480+ if (
1481+ codeSnippet . tags . includes ( tag ) ||
1482+ codeSnippet . language === tag
1483+ ) {
14721484 return true ;
14731485 }
14741486 }
@@ -1477,7 +1489,20 @@ export class CodeSnippetDisplay extends React.Component<
14771489 const indexToDelete = newMatchIndices . indexOf ( matchedIndex ) ;
14781490 newMatchIndices . splice ( indexToDelete , 1 ) ;
14791491 return false ;
1480- } ) ;
1492+ } ) /*||
1493+ languageTags.some(lang => {
1494+ if (codeSnippet.language) {
1495+ if (codeSnippet.language === lang) {
1496+ //if a snippet's language matches one of the selected ones
1497+ return true;
1498+ }
1499+ }
1500+ // if the snippet does not have the tag, remove its mathed index
1501+ const matchedIndex = matchIndices[id];
1502+ const indexToDelete = newMatchIndices.indexOf(matchedIndex);
1503+ newMatchIndices.splice(indexToDelete, 1);
1504+ return false;
1505+ })*/ ;
14811506 } ) ;
14821507 matchIndices = newMatchIndices ;
14831508 }
@@ -1495,8 +1520,11 @@ export class CodeSnippetDisplay extends React.Component<
14951520 ) ;
14961521 } ;
14971522
1498- getActiveTags ( ) : string [ ] {
1523+ getActiveTags ( ) : [ string [ ] , string [ ] ] {
1524+ //TODO: go through snippet languages and add those to a list & pass into FilterTools,
1525+ // in filterTools add a new language section and add list of lang tags there
14991526 const tags : string [ ] = [ ] ;
1527+ const languages : string [ ] = [ ] ;
15001528 for ( const codeSnippet of this . props . codeSnippets ) {
15011529 if ( codeSnippet . tags ) {
15021530 for ( const tag of codeSnippet . tags ) {
@@ -1505,8 +1533,11 @@ export class CodeSnippetDisplay extends React.Component<
15051533 }
15061534 }
15071535 }
1536+ if ( ! languages . includes ( codeSnippet . language ) ) {
1537+ languages . push ( codeSnippet . language ) ;
1538+ }
15081539 }
1509- return tags ;
1540+ return [ tags , languages ] ;
15101541 }
15111542
15121543 private deleteCommand ( codeSnippet : ICodeSnippet ) : void {
@@ -1613,7 +1644,7 @@ export class CodeSnippetDisplay extends React.Component<
16131644 editSnip . className = CODE_SNIPPET_MORE_OTPIONS_EDIT ;
16141645 editSnip . textContent = 'Edit snippet' ;
16151646 editSnip . onclick = ( ) : void => {
1616- const allTags = this . getActiveTags ( ) ;
1647+ const allTags = this . getActiveTags ( ) [ 0 ] ;
16171648 this . props . openCodeSnippetEditor ( {
16181649 name : codeSnippet . name ,
16191650 description : codeSnippet . description ,
@@ -1672,7 +1703,7 @@ export class CodeSnippetDisplay extends React.Component<
16721703 code : [ ] ,
16731704 id : this . state . codeSnippets . length ,
16741705 selectedTags : [ ] ,
1675- allTags : this . getActiveTags ( ) ,
1706+ allTags : this . getActiveTags ( ) [ 0 ] ,
16761707 fromScratch : true
16771708 } ) ;
16781709 } }
@@ -1682,7 +1713,8 @@ export class CodeSnippetDisplay extends React.Component<
16821713 </ header >
16831714 < div className = { CODE_SNIPPET_HEADER_BOX } >
16841715 < FilterTools
1685- tags = { this . getActiveTags ( ) }
1716+ languages = { this . getActiveTags ( ) [ 1 ] }
1717+ tags = { this . getActiveTags ( ) [ 0 ] }
16861718 onFilter = { this . filterSnippets }
16871719 />
16881720 </ div >
0 commit comments