List was not cycled right for tab autocompletion

This commit is contained in:
Vane11ope 2020-07-02 09:46:24 +09:00
parent e822d68e93
commit 7806a34858

View File

@ -28,15 +28,17 @@ class ListCompleter(Completer):
if o.startswith(start):
self.options.append(o)
self.options.sort()
self.offset = 0
self.pos = None
def cycle(self, forward: bool = True) -> str:
if not self.options:
return self.start
ret = self.options[self.offset]
delta = 1 if forward else -1
self.offset = (self.offset + delta) % len(self.options)
return ret
if self.pos is None:
self.pos = 0 if forward else len(self.options) - 1
else:
delta = 1 if forward else -1
self.pos = (self.pos + delta) % len(self.options)
return self.options[self.pos]
class CompletionState(typing.NamedTuple):