@@ -30,7 +30,7 @@ foam.CLASS({
3030 properties : [
3131 {
3232 name : 'baseGrammar_' ,
33- value : function ( alt , anyChar , not , opt , range , repeat , repeat0 , seq , seq1 , str , sug , sym ) {
33+ value : function ( alt , anyChar , literal , not , opt , range , repeat , repeat0 , seq , seq1 , str , sug , sym ) {
3434 // Override sug to add prepend overrides
3535 let oldSug = sug ;
3636 sug = ( v , opt ) => { return oldSug ( v , { prependSpaceOnSelect : false , ...opt } ) } ;
@@ -94,10 +94,7 @@ foam.CLASS({
9494 sym ( 'genericPropertyValue' )
9595 ) ,
9696 // Token suggestions
97- tokenValue : seq (
98- '$' ,
99- alt ( sym ( 'tokens' ) , sym ( 'tokenIdentifier' ) )
100- ) ,
97+ tokenValue : sym ( 'tokens' ) ,
10198 // CSS property value suggestions
10299 tokenIdentifier : repeat ( not ( alt ( ' ' , ';' , '\n' , '\r' , ',' ) , anyChar ( ) ) ) ,
103100 // Padding suggestions
@@ -195,11 +192,11 @@ foam.CLASS({
195192 '%'
196193 ) ,
197194 colorPropertyValue : alt (
195+ str ( seq ( sug ( literal ( '$' ) , { text : '$' , label : 'CSS Token' , prependSpaceOnSelect : false } ) , sym ( 'tokenValue' ) ) ) ,
198196 sug ( sym ( 'hexValue' ) , { view : 'foam.parse.auto.ColorSuggester' , label : 'Hex Color' } ) ,
199197 // Only one is required
200198 // sug(sym('rbgValue'), { view: 'foam.parse.auto.ColorSuggester', text: 'RGB Color' }),
201199 // sug(sym('hslValue'), { view: 'foam.parse.auto.ColorSuggester', text: 'HSL Color' }),
202- sug ( sym ( 'tokenValue' ) , { text : '$' , label : 'CSS Token' } ) ,
203200 sug ( 'transparent' , { text : 'transparent' } )
204201 )
205202 } ;
@@ -213,9 +210,17 @@ foam.CLASS({
213210 let tokenProps = [ ] ;
214211 let allTokens = foam . u2 . CSSTokens . getAxiomsByClass ( foam . u2 . CSSToken ) ;
215212 let token = ( token ) => sug ( literal ( token . name , token ) , { text : token . name , view : { class : 'foam.parse.auto.CSSTokenSuggester' , token : token } , prependSpaceOnSelect : false } ) ;
213+
214+ allTokens . sort ( ( o1 , o2 ) => {
215+ o1 = o1 . name ;
216+ o2 = o2 . name ;
217+ return ( o2 . length - o1 . length ) || foam . util . compare ( o1 , o2 ) ;
218+ } ) ;
219+
216220 allTokens . forEach ( v => {
217221 tokenProps . push ( token ( v ) ) ;
218- } )
222+ } ) ;
223+
219224 return alt . apply ( null , tokenProps ) ;
220225 // Load current theme tokens if they exist
221226 // Can this work?? Do we need this??
0 commit comments