aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/events
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/events')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/events/TabCompletionEvent.kt37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/events/TabCompletionEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/TabCompletionEvent.kt
new file mode 100644
index 000000000..f3ec47b02
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/events/TabCompletionEvent.kt
@@ -0,0 +1,37 @@
+package at.hannibal2.skyhanni.events
+
+class TabCompletionEvent(
+ val leftOfCursor: String,
+ val fullText: String,
+ val originalCompletions: List<String>,
+) : LorenzEvent() {
+ val lastWord = leftOfCursor.substringAfterLast(' ')
+ val additionalSuggestions = mutableSetOf<String>()
+ val suppressedSuggestions = mutableSetOf<String>()
+
+ fun addSuggestion(suggestion: String) {
+ if (suggestion.startsWith(lastWord, ignoreCase = true))
+ additionalSuggestions.add(suggestion)
+ }
+
+ fun addSuggestions(suggestions: Iterable<String>) {
+ 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<String>? {
+ if (additionalSuggestions.isEmpty() && suppressedSuggestions.isEmpty()) return null
+ return (originalCompletions - suppressedSuggestions + additionalSuggestions).toTypedArray()
+ }
+}