Skip to content

fix(buffer): regenerate auto-suggestion after text changes such as deletions - #2139

Open
saadkhantareen wants to merge 1 commit into
prompt-toolkit:mainfrom
saadkhantareen:fix/auto-suggest-after-delete
Open

saadkhantareen wants to merge 1 commit into
prompt-toolkit:mainfrom
saadkhantareen:fix/auto-suggest-after-delete

Conversation

@saadkhantareen

Copy link
Copy Markdown

Summary

The auto suggester of a Buffer was only invoked from insert_text. Every text change clears the current suggestion in Buffer._text_changed, so after deleting text (backspace, delete, cut, undo, ...) the suggestion disappeared and was never regenerated until the user typed again. This change asks the auto suggester for a new suggestion on every text change, mirroring how input validation is already re-run from _text_changed.

Fixes #2016

Changes

  • src/prompt_toolkit/buffer.py: in Buffer._text_changed, schedule the existing _async_suggester coroutine whenever auto_suggest is set, alongside the existing validation scheduling. This covers all mutation paths that go through _text_changed (deletions, undo/redo, set_document, text assignment), not just insertions. When text changes through insert_text, the suggester can be scheduled twice; that is harmless because the coroutine is guarded to run only one at a time and returns early when a suggestion is already present.
  • tests/test_buffer.py: new regression test test_auto_suggest_after_delete with a recording AutoSuggest stub. It asserts that a suggestion is generated after typing, and that after delete_before_cursor a new suggestion is generated for the remaining text.

Tests

  • python -m pytest tests/test_buffer.py -v — 10 passed, including the new test_auto_suggest_after_delete (fails without the fix: the suggestion stays None after deletion).
  • python -m pytest tests/ -q — 157 passed (full suite, including tests/test_memory_leaks.py).
  • python -m black --check src/prompt_toolkit/buffer.py tests/test_buffer.py — both files unchanged (formatting clean).

Copilot AI balanced review requested due to automatic review settings October 14, 2026 10:14

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Auto suggestions not called after text deletion

2 participants