Skip to content

Preserve cursor position when pasting an empty clipboard in Vi mode - #2133

Open
FanWu-ai wants to merge 1 commit into
prompt-toolkit:mainfrom
FanWu-ai:fix-empty-clipboard-cursor-20261011
Open

FanWu-ai wants to merge 1 commit into
prompt-toolkit:mainfrom
FanWu-ai:fix-empty-clipboard-cursor-20261011

Conversation

@FanWu-ai

Copy link
Copy Markdown

Pressing P with the default empty clipboard moves the cursor one character left even though no text was inserted. A following edit consequently acts on the wrong character: abcd, Escape, P, x produces abd instead of abc. Direct Document use can also return a negative cursor at the beginning.

Apply the paste-before cursor adjustment only when characterwise clipboard data is nonempty. Empty linewise data still inserts a blank line. Add direct document regressions and real PromptSession tests for P and 3P, with controls for other paste modes and linewise data.

Validation on Linux / Python 3.12.14:

  • Pristine full suite: 156 passed.
  • Six new regression cases fail against the original implementation; ten controls pass.
  • Final full suite under coverage: 172 passed.
  • Ruff lint/format, typos, strict mypy for Linux/Windows/macOS, all 12 pinned hooks, wheel/sdist builds, and git diff --check passed.
  • Differential checks cover 42 corrected cases and 1,470 unaffected combinations; packaged source matches tested source.
  • An independent 135-case empty-paste identity check passes.

Builds emit existing setuptools license-classifier deprecation warnings. Other Python versions and native operating systems were not run locally; mypy platform targets are static checks. Hosted CI has not run yet.

AI assistance was used to investigate the bug and prepare the implementation and regression tests.

AI assistance: OpenAI Codex was used for investigation, implementation, regression tests, and automated validation.
@FanWu-ai
FanWu-ai marked this pull request as ready for review October 11, 2026 16:14
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.

1 participant