Skip to content

Commit

Permalink
Added nick completion with Tab
Browse files Browse the repository at this point in the history
  • Loading branch information
Ole Andre Birkedal committed Dec 28, 2019
1 parent 551ac34 commit 75e3070
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions ui/channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"github.com/gdamore/tcell"
"github.com/rivo/tview"
"strings"
)

type channel struct {
Expand Down Expand Up @@ -90,6 +91,22 @@ func (v *View) AddChannel(name, topic string, cid, bid int, userList []string) {
v.sendToBuffer(cid, name, newChan.input.GetText())
newChan.input.SetText("")
}

if key == tcell.KeyTab {
currText := newChan.input.GetText()
words := strings.Split(currText, " ")

if len(words) > 0 {
lastWord := words[len(words) - 1]
foundUsersIdxs := newChan.users.FindItems(lastWord, lastWord, false, true)

if len(foundUsersIdxs) > 0 {
foundUser, _ := newChan.users.GetItemText(foundUsersIdxs[0])
newInput := strings.Join(append(words[:len(words) - 1], foundUser), " ")
newChan.input.SetText(newInput)
}
}
}
})

v.app.QueueUpdateDraw(func() {
Expand Down

0 comments on commit 75e3070

Please # to comment.