Skip to content

Restore next-history selection after Ctrl-O - #2173

Open
ViktorBystrov72 wants to merge 1 commit into
prompt-toolkit:mainfrom
ViktorBystrov72:fix/operate-get-next-history
Open

ViktorBystrov72 wants to merge 1 commit into
prompt-toolkit:mainfrom
ViktorBystrov72:fix/operate-get-next-history

Conversation

@ViktorBystrov72

Copy link
Copy Markdown

Fixes #1936 and #1504.

Ctrl-O accepts the selected history entry, but the next prompt remains empty: the saved history index is applied before the buffer's asynchronous history load has populated its working lines.

Select the next entry after that load completes. Keep the position relative to the end so partially loaded history and duplicate entries retain the correct position, accounting for whether accepting the command appended a history entry. Skip the pending selection if the user has already edited or navigated the next prompt, and don't queue it when validation rejects Ctrl-O.

The 14 regression cases use real PromptSession input, both InMemoryHistory and ThreadedHistory, duplicate commands, explicitly paused history loads, intervening typing/navigation, and rejected validation. Synchronization uses events, not timing sleeps. Nine cases fail on unmodified main and five are passing controls; all pass with the fix.

Validation on macOS, Python 3.13.13:

  • Complete suite: 170 passed.
  • Ruff check and format, typos, and git diff --check passed.
  • Strict mypy passed for win32, linux, and darwin (145 source files each). These are static platform checks, not Windows/Linux runtime runs.

OpenAI Codex assisted with implementation, tests, and this description. The reported checks were run locally; no human review is claimed.

Apply the next history position after the following prompt finishes
loading its history. Track the position from the end so partially loaded
history and appending the accepted command do not shift the target.

Only schedule the operation after successful validation. Leave the
buffer alone if the user edits it or selects another history entry while
loading. Ignore stale, cancelled, and failed history loads.

Add prompt-session regressions for memory and threaded history, partial
loads, duplicate entries, input during loading, and validation failure.
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.

operate-and-get-next example does not work

1 participant