From efb4d476a5c54e4d6812eaa56d92e927a378fe26 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Sat, 29 Aug 2020 18:19:00 +0200 Subject: [PATCH] Autocomplete: Only return the end of the current word (or the next one if the current word is finished) --- plugins/Autocomplete/plugin.py | 15 ++++++++++++--- plugins/Autocomplete/test.py | 5 ++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/plugins/Autocomplete/plugin.py b/plugins/Autocomplete/plugin.py index 041212252..7a734c0d3 100644 --- a/plugins/Autocomplete/plugin.py +++ b/plugins/Autocomplete/plugin.py @@ -59,9 +59,18 @@ def _getAutocompleteResponse(irc, msg, payload): # strip what the user already typed assert all(candidate.startswith(normalized_payload) for candidate in candidates) normalized_payload_length = len(normalized_payload) - response_items = [candidate[normalized_payload_length:] for candidate in candidates] - response_items.sort() - return "\t".join(response_items) + candidate_commands = [ + candidate[normalized_payload_length:] for candidate in candidates + ] + + 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): diff --git a/plugins/Autocomplete/test.py b/plugins/Autocomplete/test.py index c738c0e37..68355c409 100644 --- a/plugins/Autocomplete/test.py +++ b/plugins/Autocomplete/test.py @@ -67,10 +67,13 @@ class AutocompleteTestCase(PluginTestCase): with conf.supybot.plugins.Autocomplete.enabled.context(True): self._assertAutocompleteResponse("apro", "pos") self._assertAutocompleteResponse("apr", "opos") - self._assertAutocompleteResponse("te", "ll\tstplugin eval") + self._assertAutocompleteResponse("te", "ll\tstplugin") self._assertAutocompleteResponse("tel", "l") + self._assertAutocompleteResponse("mi", "sc") self._assertAutocompleteResponse("misc t", "ell") self._assertAutocompleteResponse("misc c", "learmores\tompletenick") + self._assertAutocompleteResponse("lat", "er") + self._assertAutocompleteResponse("later", "notes\tremove\ttell\tundo") def testNoResponse(self): with conf.supybot.protocols.irc.experimentalExtensions.context(True):