After the introduction of the tab complete feature, the tab
key can no longer be used to navigate away from the chatbox.
This commit adds a shift+tab function to navigate away from
the chatbox, rather than tab completing a name.
This commit implements a feature commonly found in IRC clients
and often referred to as "tab complete". This allows a user to
type part of a user's name in the chat box and then press tab, which
causes the program to complete the user's name in the chat box. The
user can then press tab additional times in order to cycle through
the list of possible matches.
Tab complete has been implemented for the main chat, for battles,
and for private messages.
The algorithm implemented is that when you press tab, the program
looks backward to the last space (or start of the line) and
considers the substring between the last space and the position of
the cursor to be the prefix of a name. It then builds a list of
all names that it could be, which is then sorted. The sort is
done first based on activity (i.e. users who have spoken more
recently are sorted higher), and if users are tied as to activity,
then by alphabetical order.
After a name has been tab-completed, you can then press tab
subsequent times in order to cycle through the remainder of the list.
The idea behind this algorithm is that a user will usually want
to refer to somebody who has spoken recently in the chat. This
is especially helpful for Pokemon Showdown because with 1500+
users, it would be difficult to complete the correct name if it
were based purely on alphabetical order.
Matching of names is based on userids, which are strictly
alphanumeric. Therefore, when intending to use tab complete,
a user should type only the letters and numbers from a user's
name, not any spaces or symbols. After pressing tab, the spaces
and symbols will appear in the chatbox, however.