Skip to content

Handle empty content in numbered margins - #2130

Open
FanWu-ai wants to merge 1 commit into
prompt-toolkit:mainfrom
FanWu-ai:fix-numbered-margin-empty-content
Open

FanWu-ai wants to merge 1 commit into
prompt-toolkit:mainfrom
FanWu-ai:fix-numbered-margin-empty-content

Conversation

@FanWu-ai

@FanWu-ai FanWu-ai commented Oct 9, 2026

Copy link
Copy Markdown

NumberedMargin(display_tildes=True) crashes with UnboundLocalError when a control returns zero lines of content. This occurs during normal Window.write_to_screen rendering: the loop never assigns its row index, but tilde filling reads that index afterward.

Count displayed rows explicitly and fill the remaining window rows. This also avoids emitting one extra tilde row for nonempty or wrapped content.

The 15 regression cases exercise real window rendering with empty content, left/right margins, relative numbering, tilde-disabled controls, short/full/overflowing content, and wrapped lines. Before the fix, 10 fail and five controls pass; afterward all 15 pass.

Validation on Linux, Python 3.12.14:

  • Fresh pristine full suite: 156 passed.
  • Final full suite under coverage: 171 passed, no skips or warnings.
  • Ruff lint/format, standalone typos, strict mypy for Windows/Linux/macOS, and all applicable repository hooks passed, including an explicit check of the new test file.
  • Wheel/sdist builds passed; packaged implementation matches tested source.
  • git diff --check passed.

Builds emit the existing setuptools license-classifier deprecation warning. Other Python versions and native operating systems were not run locally. Hosted CI is not claimed as passed.

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

@FanWu-ai
FanWu-ai marked this pull request as ready for review October 9, 2026 21:33
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