Auto suggestions not called after text deletion

Open
#2,016 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
cli

Research direction

Reproduce the behavior with the PromptSession and AutoSuggestFoo example, then inspect src/prompt_toolkit/widgets/base.py around lines 235-246 and trace what happens after deletion. Check whether the buffer loses focus, is_done changes, or input processing is skipped; done means the unconditional suggestion remains visible after text is deleted.

Written by the indexing model from the issue text.

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 https://github.com/prompt-toolkit/python-prompt-toolkit/blob/d8adbe9bfcf5f7e95b015d8ab12e2985b9a7822b/src/prompt_toolkit/widgets/base.py#L235-L246

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.

Dominant language
Python
Stars
10.6k
Forks
815
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from prompt-toolkit/python-prompt-toolkit

All issues in prompt-toolkit/python-prompt-toolkit

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.