added logic for emoji tab completion
This commit is contained in:
26
main.go
26
main.go
@ -265,7 +265,7 @@ func stringRemainder(aStr, bStr string) string {
|
|||||||
return long[i:]
|
return long[i:]
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateTabCompletionSlice(inputWord string) []string {
|
func generateChannelTabCompletionSlice(inputWord string) []string {
|
||||||
// create a slice to hold the values
|
// create a slice to hold the values
|
||||||
var firstSlice []string
|
var firstSlice []string
|
||||||
// iterate over all the conversation results
|
// iterate over all the conversation results
|
||||||
@ -284,6 +284,12 @@ func generateTabCompletionSlice(inputWord string) []string {
|
|||||||
return resultSlice
|
return resultSlice
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func generateEmojiTabCompletionSlice(inputWord string) []string {
|
||||||
|
// use the emojiSlice from emojiList.go and filter it for the input word
|
||||||
|
resultSlice := filterStringSlice(emojiSlice, inputWord)
|
||||||
|
return resultSlice
|
||||||
|
}
|
||||||
|
|
||||||
func handleTab() error {
|
func handleTab() error {
|
||||||
inputString, err := getInputString("Input")
|
inputString, err := getInputString("Input")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -292,14 +298,22 @@ func handleTab() error {
|
|||||||
// if you successfully get an input string, grab the last word from the string
|
// if you successfully get an input string, grab the last word from the string
|
||||||
ss := strings.Split(inputString, " ")
|
ss := strings.Split(inputString, " ")
|
||||||
s := ss[len(ss)-1]
|
s := ss[len(ss)-1]
|
||||||
// now in case the word (s) is a mention @something, lets remove it to normalize
|
// create a variable in which to store the result
|
||||||
if strings.HasPrefix(s, "@") {
|
var resultSlice []string
|
||||||
s = strings.Replace(s, "@", "", 1)
|
// if the word starts with a : its an emoji lookup
|
||||||
|
if strings.HasPrefix(s, ":") {
|
||||||
|
resultSlice = generateEmojiTabCompletionSlice(s)
|
||||||
|
} else {
|
||||||
|
// now in case the word (s) is a mention @something, lets remove it to normalize
|
||||||
|
if strings.HasPrefix(s, "@") {
|
||||||
|
s = strings.Replace(s, "@", "", 1)
|
||||||
|
}
|
||||||
|
// now call get the list of all possible cantidates that have that as a prefix
|
||||||
|
resultSlice = generateChannelTabCompletionSlice(s)
|
||||||
}
|
}
|
||||||
// now call get the list of all possible cantidates that have that as a prefix
|
|
||||||
resultSlice := generateTabCompletionSlice(s)
|
|
||||||
lcp := longestCommonPrefix(resultSlice)
|
lcp := longestCommonPrefix(resultSlice)
|
||||||
if lcp != "" {
|
if lcp != "" {
|
||||||
|
printToView("Feed", fmt.Sprintf("%d tab completion options", len(resultSlice)))
|
||||||
remainder := stringRemainder(s, lcp)
|
remainder := stringRemainder(s, lcp)
|
||||||
writeToView("Input", remainder)
|
writeToView("Input", remainder)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user