Conversation
Fixes prompt-toolkit#1185. When accept_handler returns True (keep_text), the buffer was previously not reset at all, which left _load_history_task unchanged and prevented newly appended history entries from being loaded into _working_lines. Reset the buffer with the current document to properly reset transient state and trigger history reloading, while avoiding duplicate working lines when the latest history item matches the working line.
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.
Problem
Fixes #1185.
When
accept_handlerreturnsTrue(keep_text), the buffer was previously bypassed from callingself.reset(). While this succeeded in preserving the text in the buffer, it had severe unintended side effects:_load_history_taskwas never reset toNone, so newly appended history entries fromself.append_to_history()were never loaded intoself._working_lines.history_backward()/history_forward()(using the Up/Down arrow keys) failed to navigate any history entries.Solution
validate_and_handle, whenkeep_textisTrue, callself.reset(document=Document(self.text, self.cursor_position)). This resets transient states and clears_load_history_taskso history can reload on the next render.load_history, avoid duplicating the working line when it is already identical to the most recent history item.tests/test_buffer.pyto verify that history navigation works as expected across multiple accepts withkeep_text=True.