primitivus (chat): fixed nick completion. Completion is now managed per widget, if completion method exists
This commit is contained in:
parent
04515e5013
commit
22d70f23c4
1 changed files with 34 additions and 27 deletions
|
|
@ -156,6 +156,10 @@ class OccupantWidget(urwid.WidgetWrap):
|
|||
def parent(self):
|
||||
return self.mess_data.parent
|
||||
|
||||
@property
|
||||
def nick(self):
|
||||
return self.occupant_data.nick
|
||||
|
||||
def selectable(self):
|
||||
return True
|
||||
|
||||
|
|
@ -253,6 +257,29 @@ class Chat(PrimitivusWidget, quick_chat.QuickChat):
|
|||
|
||||
return super(Chat, self).keypress(size, key)
|
||||
|
||||
def completion(self, text, completion_data):
|
||||
"""Completion method which complete nicknames in group chat
|
||||
|
||||
for params, see [sat_widgets.AdvancedEdit]
|
||||
"""
|
||||
if self.type != C.CHAT_GROUP:
|
||||
return text
|
||||
|
||||
space = text.rfind(" ")
|
||||
start = text[space + 1:]
|
||||
words = [w.nick for w in self.occupants_walker if isinstance(w, OccupantWidget) and w.nick.startswith(start)]
|
||||
if not words:
|
||||
return text
|
||||
try:
|
||||
word_idx = words.index(completion_data['last_word']) + 1
|
||||
except (KeyError, ValueError):
|
||||
word_idx = 0
|
||||
else:
|
||||
if word_idx == len(words):
|
||||
word_idx = 0
|
||||
word = completion_data['last_word'] = words[word_idx]
|
||||
return u"{}{}{}".format(text[:space + 1], word, ': ' if space < 0 else '')
|
||||
|
||||
def getMenu(self):
|
||||
"""Return Menu bar"""
|
||||
menu = sat_widgets.Menu(self.host.loop)
|
||||
|
|
|
|||
Loading…
Reference in a new issue