-
Notifications
You must be signed in to change notification settings - Fork 741
Description
The autosuggester for a buffer does not seem to be called after deleting text from the buffer. Instead, it is only called when inserting text.
Demonstration:
from prompt_toolkit.auto_suggest import AutoSuggest, Suggestion
from prompt_toolkit import PromptSession
def main():
session = PromptSession(
auto_suggest=AutoSuggestFoo(),
)
while True:
try:
text = session.prompt("Say something: ")
except KeyboardInterrupt:
pass # Ctrl-C pressed. Try again.
else:
break
print(f"You said: {text}")
class AutoSuggestFoo(AutoSuggest):
"""
Give suggestions based on the lines in the history.
"""
def get_suggestion(self, buffer, document):
return Suggestion(" example completion")
Expected behavior:
example completion
should be shown at the end of the prompt at all times, since the completer is not conditional and it always returns example completion
Actual behavior:
example completion
is only shown at the end of the prompt when we are typing text. If we delete text, the suggestion goes away until we start typing again
Diagnosis:
It seems like the completion is applied in
python-prompt-toolkit/src/prompt_toolkit/widgets/base.py
Lines 235 to 246 in d8adbe9
self.control = BufferControl( | |
buffer=self.buffer, | |
lexer=DynamicLexer(lambda: self.lexer), | |
input_processors=[ | |
ConditionalProcessor( | |
AppendAutoSuggestion(), has_focus(self.buffer) & ~is_done | |
), | |
ConditionalProcessor( | |
processor=PasswordProcessor(), filter=to_filter(password) | |
), | |
BeforeInput(prompt, style="class:text-area.prompt"), | |
] |
Does the buffer somehow lose focus or is_done
become true after deleting?
Are input_processor in a buffer only applied to newly typed text? Does this mean that all formatting doesn't get reapplied on deletion?
Is
I'm happy to trace this more, but if someone can say whether this is intentional behavior (and if so is it explicitly implemented or a consequence of the architecture) that would be very helpful. Debugging async code to determine why this the input_processor isn't being called is a bit hard.