Repository navigation
fix(buffer): regenerate auto-suggestion after text changes such as deletions - #2139
Open
saadkhantareen wants to merge 1 commit into
Open
saadkhantareen wants to merge 1 commit into
saadkhantareen wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The auto suggester of a
Bufferwas only invoked frominsert_text. Every text change clears the current suggestion inBuffer._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: inBuffer._text_changed, schedule the existing_async_suggestercoroutine wheneverauto_suggestis 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 throughinsert_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 testtest_auto_suggest_after_deletewith a recordingAutoSuggeststub. It asserts that a suggestion is generated after typing, and that afterdelete_before_cursora new suggestion is generated for the remaining text.Tests
python -m pytest tests/test_buffer.py -v— 10 passed, including the newtest_auto_suggest_after_delete(fails without the fix: the suggestion staysNoneafter deletion).python -m pytest tests/ -q— 157 passed (full suite, includingtests/test_memory_leaks.py).python -m black --check src/prompt_toolkit/buffer.py tests/test_buffer.py— both files unchanged (formatting clean).