Autocomplete: Only return the end of the current word (or the next one if the current word is finished)

This commit is contained in:
Valentin Lorentz 2020-08-29 18:19:00 +02:00
parent fbf9f0166d
commit efb4d476a5
2 changed files with 16 additions and 4 deletions

View File

@ -59,9 +59,18 @@ def _getAutocompleteResponse(irc, msg, payload):
# strip what the user already typed # strip what the user already typed
assert all(candidate.startswith(normalized_payload) for candidate in candidates) assert all(candidate.startswith(normalized_payload) for candidate in candidates)
normalized_payload_length = len(normalized_payload) normalized_payload_length = len(normalized_payload)
response_items = [candidate[normalized_payload_length:] for candidate in candidates] candidate_commands = [
response_items.sort() candidate[normalized_payload_length:] for candidate in candidates
return "\t".join(response_items) ]
tokenized_candidates = [
callbacks.tokenize(c, channel=msg.channel, network=irc.network)
for c in candidate_commands
]
response_items = {candidate[0] for candidate in tokenized_candidates}
return "\t".join(sorted(response_items))
def _getCandidates(irc, normalized_payload): def _getCandidates(irc, normalized_payload):

View File

@ -67,10 +67,13 @@ class AutocompleteTestCase(PluginTestCase):
with conf.supybot.plugins.Autocomplete.enabled.context(True): with conf.supybot.plugins.Autocomplete.enabled.context(True):
self._assertAutocompleteResponse("apro", "pos") self._assertAutocompleteResponse("apro", "pos")
self._assertAutocompleteResponse("apr", "opos") self._assertAutocompleteResponse("apr", "opos")
self._assertAutocompleteResponse("te", "ll\tstplugin eval") self._assertAutocompleteResponse("te", "ll\tstplugin")
self._assertAutocompleteResponse("tel", "l") self._assertAutocompleteResponse("tel", "l")
self._assertAutocompleteResponse("mi", "sc")
self._assertAutocompleteResponse("misc t", "ell") self._assertAutocompleteResponse("misc t", "ell")
self._assertAutocompleteResponse("misc c", "learmores\tompletenick") self._assertAutocompleteResponse("misc c", "learmores\tompletenick")
self._assertAutocompleteResponse("lat", "er")
self._assertAutocompleteResponse("later", "notes\tremove\ttell\tundo")
def testNoResponse(self): def testNoResponse(self):
with conf.supybot.protocols.irc.experimentalExtensions.context(True): with conf.supybot.protocols.irc.experimentalExtensions.context(True):