Skip to content

Align expanded tabs with terminal columns after wide characters - #2146

Open
FanWu-ai wants to merge 1 commit into
prompt-toolkit:mainfrom
FanWu-ai:fix/tabs-rendered-columns-20261019
Open

FanWu-ai wants to merge 1 commit into
prompt-toolkit:mainfrom
FanWu-ai:fix/tabs-rendered-columns-20261019

Conversation

@FanWu-ai

Copy link
Copy Markdown

Problem

TabsProcessor uses the transformed string index to calculate tab stops. String indexes and terminal columns differ after double-width and combining characters. For example, with tabstop=4, 界\tb currently expands to 界 b, placing b in terminal column 5 instead of 4.

Change

Track terminal columns separately from transformed string positions. Use the renderer's cached character widths, including control-character display mappings, to determine the next tab stop while keeping source/display mappings expressed as string indexes. Preserve zero-width escape fragments without counting or expanding their contents.

Regression coverage

Cover ASCII, wide characters before the first and repeated tabs, a wide-character sequence ending exactly on a tab stop, combining characters, C0/C1 control-character rendering, and zero-width escape sequences (including a literal tab inside an OSC sequence). Check the expanded text and both cursor-position mappings, including positions inside tab expansion.

AI-assisted implementation; the patch and test results were reviewed.

Validation

  • Unmodified base: 156 tests passed; project lint, formatting, spelling, all three strict mypy platform checks and all pre-commit hooks passed.
  • Regression against unmodified TabsProcessor: 8 failed, 1 passed.
  • Fixed tree: 165 tests passed; ruff check, ruff format --check, typos, mypy --strict for win32/linux/darwin, all 12 prek hooks, and git diff --check passed.
  • Independently reviewed, including additional actual Window rendering and mouse-mapping checks.
  • Local runtime: Python 3.12.14 on Linux. Hosted CI has not yet run for this PR.

Commands run successfully against the final tree:

.venv/bin/coverage run -m pytest tests/
.venv/bin/ruff check .
.venv/bin/ruff format --check .
.venv/bin/typos .
.venv/bin/mypy --strict src/ --platform win32
.venv/bin/mypy --strict src/ --platform linux
.venv/bin/mypy --strict src/ --platform darwin
PREK_HOME=/tmp/prek-c .venv/bin/prek run --all-files
git diff --check

Packaging validation: .venv/bin/python -m build passed in an isolated build environment and produced both the sdist and wheel. Setuptools emitted deprecation warnings concerning upstream license classifiers; the build completed successfully.

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