Merge pull request #355 from pavelz/my_name_last_autocomplete

main: Autocomplete deprioritize own name
This commit is contained in:
Andrey Petrov 2020-07-30 12:03:35 -04:00 committed by GitHub
commit fa8df8140d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 5 deletions

View File

@ -258,5 +258,11 @@ func (a RecentActiveUsers) Less(i, j int) bool {
defer a[i].mu.Unlock()
a[j].mu.Lock()
defer a[j].mu.Unlock()
return a[i].lastMsg.After(a[j].lastMsg)
if a[i].lastMsg.IsZero() {
return a[i].joined.Before(a[j].joined)
} else {
return a[i].lastMsg.Before(a[j].lastMsg)
}
}

13
host.go
View File

@ -243,14 +243,19 @@ func (h *Host) Serve() {
h.listener.Serve()
}
func (h *Host) completeName(partial string) string {
func (h *Host) completeName(partial string, skipName string) string {
names := h.NamesPrefix(partial)
if len(names) == 0 {
// Didn't find anything
return ""
} else if name := names[0]; name != skipName {
// First name is not the skipName, great
return name
} else if len(names) > 1 {
// Next candidate
return names[1]
}
return names[len(names)-1]
return ""
}
func (h *Host) completeCommand(partial string) string {
@ -300,7 +305,7 @@ func (h *Host) AutoCompleteFunction(u *message.User) func(line string, pos int,
}
} else {
// Name
completed = h.completeName(partial)
completed = h.completeName(partial, u.Name())
if completed == "" {
return
}