package at.hannibal2.skyhanni.events class TabCompletionEvent( val leftOfCursor: String, val fullText: String, val originalCompletions: List, ) : LorenzEvent() { val lastWord = leftOfCursor.substringAfterLast(' ') val additionalSuggestions = mutableSetOf() val suppressedSuggestions = mutableSetOf() fun addSuggestion(suggestion: String) { if (suggestion.startsWith(lastWord, ignoreCase = true)) additionalSuggestions.add(suggestion) } fun addSuggestions(suggestions: Iterable) { suggestions.forEach(this::addSuggestion) } fun excludeAllDefault() { suppressedSuggestions.addAll(originalCompletions) } val command = if (leftOfCursor.startsWith("/")) leftOfCursor.substring(1).substringBefore(" ").lowercase() else "" fun isCommand(commandName: String): Boolean { return commandName.equals(command, ignoreCase = true) } fun intoSuggestionArray(): Array? { if (additionalSuggestions.isEmpty() && suppressedSuggestions.isEmpty()) return null return (originalCompletions - suppressedSuggestions + additionalSuggestions).toTypedArray() } }