✨ added support to list all gitmojis
This commit is contained in:
		
							parent
							
								
									4ed2d152f8
								
							
						
					
					
						commit
						16f38ce21b
					
				
							
								
								
									
										38
									
								
								__init__.py
									
									
									
									
									
								
							
							
						
						
									
										38
									
								
								__init__.py
									
									
									
									
									
								
							| @ -2,7 +2,9 @@ | ||||
| 
 | ||||
| """gitmoji Picker for Albert | ||||
| Usage: g: gitmoji name or description | ||||
| Example: g: bug""" | ||||
| Examples: | ||||
|     g:bug | ||||
|     g:*""" | ||||
| 
 | ||||
| from albertv0 import * | ||||
| 
 | ||||
| @ -31,22 +33,32 @@ def initialize(): | ||||
|         gitmojis.append(gitmoji) | ||||
| 
 | ||||
| def handleQuery(query): | ||||
|     needles = query.string.lower().split() | ||||
|     if not query.isValid or not query.isTriggered: | ||||
|         return [] | ||||
| 
 | ||||
|     matches = [] | ||||
|     for gitmoji in gitmojis: | ||||
|         matchCount = count_matches(gitmoji["tokens"], needles) | ||||
|         if matchCount > 0: | ||||
|             result = dict() | ||||
|             result.update(gitmoji) | ||||
|             result["matchCount"] = matchCount | ||||
|             matches.append(result) | ||||
|     if query.string == "*": | ||||
|         matches = gitmojis | ||||
|     else: | ||||
|         needles = query.string.lower().split() | ||||
| 
 | ||||
|     matches = sorted(matches, key=lambda data: data["matchCount"], reverse=True) | ||||
|         matches = [] | ||||
|         for gitmoji in gitmojis: | ||||
|             matchCount = count_matches(gitmoji["tokens"], needles) | ||||
|             if matchCount > 0: | ||||
|                 result = dict() | ||||
|                 result.update(gitmoji) | ||||
|                 result["matchCount"] = matchCount | ||||
|                 matches.append(result) | ||||
| 
 | ||||
|     if query.isValid and query.isTriggered: | ||||
|         if not query.isValid: | ||||
|             return [] | ||||
| 
 | ||||
|         matches = sorted(matches, key=lambda data: data["matchCount"], reverse=True) | ||||
| 
 | ||||
|     if query.isValid: | ||||
|         return [Item(id=match["name"], completion=match["name"], icon=match["emoji"], text=match["emoji"] + " " + match["code"], subtext=match["description"], actions=[ClipAction("Copy to clipboard", match["code"])]) for match in matches] | ||||
|     return [] | ||||
|     else: | ||||
|         return [] | ||||
| 
 | ||||
| def count_matches(tokens, needles): | ||||
|     count = 0 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user