From 508b4ea280c60a855ccbc3dff8c27c775aec067a Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Tue, 20 Mar 2018 16:03:05 +0200 Subject: Add colon after username completion at beginning of line --- ui/view-main.go | 7 ++++++- ui/widget/room-view.go | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'ui') diff --git a/ui/view-main.go b/ui/view-main.go index 2cb8d60..707fd95 100644 --- a/ui/view-main.go +++ b/ui/view-main.go @@ -122,7 +122,12 @@ func (view *MainView) InputTabComplete(text string, cursorOffset int) string { word := findWordToTabComplete(str) userCompletions := roomView.AutocompleteUser(word) if len(userCompletions) == 1 { - text = str[0:len(str)-len(word)] + userCompletions[0] + text[len(str):] + startIndex := len(str)-len(word) + completion := userCompletions[0] + if startIndex == 0 { + completion = completion + ": " + } + text = str[0:startIndex] + completion + text[len(str):] } else if len(userCompletions) > 1 && len(userCompletions) < 6 { roomView.SetStatus(fmt.Sprintf("Completions: %s", strings.Join(userCompletions, ", "))) } diff --git a/ui/widget/room-view.go b/ui/widget/room-view.go index 1fb19c7..316fcef 100644 --- a/ui/widget/room-view.go +++ b/ui/widget/room-view.go @@ -102,8 +102,12 @@ func (view *RoomView) SetTyping(users []string) { } func (view *RoomView) AutocompleteUser(existingText string) (completions []string) { + textWithoutPrefix := existingText + if strings.HasPrefix(existingText, "@") { + textWithoutPrefix = existingText[1:] + } for _, user := range view.Room.GetMembers() { - if strings.HasPrefix(user.DisplayName, existingText) { + if strings.HasPrefix(user.DisplayName, textWithoutPrefix) { completions = append(completions, user.DisplayName) } else if strings.HasPrefix(user.UserID, existingText) { completions = append(completions, user.UserID) -- cgit v1.2.3