mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-04-15 00:20:37 +03:00
Merge pull request #355 from pavelz/my_name_last_autocomplete
main: Autocomplete deprioritize own name
This commit is contained in:
commit
fa8df8140d
@ -258,5 +258,11 @@ func (a RecentActiveUsers) Less(i, j int) bool {
|
|||||||
defer a[i].mu.Unlock()
|
defer a[i].mu.Unlock()
|
||||||
a[j].mu.Lock()
|
a[j].mu.Lock()
|
||||||
defer a[j].mu.Unlock()
|
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
13
host.go
@ -243,14 +243,19 @@ func (h *Host) Serve() {
|
|||||||
h.listener.Serve()
|
h.listener.Serve()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Host) completeName(partial string) string {
|
func (h *Host) completeName(partial string, skipName string) string {
|
||||||
names := h.NamesPrefix(partial)
|
names := h.NamesPrefix(partial)
|
||||||
if len(names) == 0 {
|
if len(names) == 0 {
|
||||||
// Didn't find anything
|
// Didn't find anything
|
||||||
return ""
|
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 ""
|
||||||
return names[len(names)-1]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Host) completeCommand(partial string) string {
|
func (h *Host) completeCommand(partial string) string {
|
||||||
@ -300,7 +305,7 @@ func (h *Host) AutoCompleteFunction(u *message.User) func(line string, pos int,
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Name
|
// Name
|
||||||
completed = h.completeName(partial)
|
completed = h.completeName(partial, u.Name())
|
||||||
if completed == "" {
|
if completed == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user