Fix RTL/LTR text overflow in overlay transcript#24
Open
Abdulrhman-92 wants to merge 1 commit into
Open
Conversation
Mixed bidirectional content (e.g., 'cpp_str المعكوس') would exceed the overlay frame boundaries because the previous wrapping logic didn't account for Unicode UAX dbachelder#9 bidi rules. Changes: - extensions/btw.ts: - wrapTranscript() uses bidiWrapText for bidi content (fast path for pure LTR) - fitRenderedLine() uses bidiVisibleWidth + bidiTruncate for accurate width measurement and safe truncation - Added containsBidi() helper for fast RTL detection - lib/bidi-wrap.ts (new): - Core bidi module with wrapWithIsolates, splitRuns, bidiWrapText, bidiTruncate, bidiVisibleWidth, isRtlChar, isBidiContent, detectDirection, normalizeBidi - tests/bidi-wrap.test.ts (new): - 25 visual regression tests covering pure Arabic, pure English, mixed RTL/LTR, code identifiers, multi-paragraph, edge cases - CHANGELOG.md (new): - Documented the fix - README.md: - Added bidi-correct rendering feature - tsconfig.json, package.json: - Include lib/ directory in build and distribution All 81 tests pass (56 existing + 25 new).
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.
Summary
Fixes the bug where mixed RTL (Arabic, Hebrew, Persian) and LTR (English,
code) text would overflow the BTW overlay frame boundaries because the
existing wrapping logic used
wrapTextWithAnsi()which is byte-width basedand doesn't handle Unicode UAX #9 bidirectional rules.
Closes #23.
Changes
extensions/btw.tswrapTranscript()now usesbidiWrapText()for lines containing RTLcharacters. Pure-LTR lines continue to use
wrapTextWithAnsi()forzero-overhead performance.
fitRenderedLine()usesbidiVisibleWidth()andbidiTruncate()foraccurate width measurement and bidi-safe truncation.
containsBidi()helper method for fast RTL detection.lib/bidi-wrap.ts(new, 480 lines)A self-contained bidi text processing module ported from the Python
format.pyhelper in thebidi-text-formattingskill:wrapWithIsolates(text)— wraps each RTL/LTR run with U+2068/U+2069splitRuns(text)— classifies text into directional runsbidiWrapText(text, width)— width-aware wrapping preserving ANSIbidiTruncate(text, width, ellipsis?)— width-aware truncationbidiVisibleWidth(text)— display width ignoring markers/ANSIisRtlChar(ch)/isBidiContent(text)— classification helpersdetectDirection(text)/normalizeBidi(text)— utility helperstests/bidi-wrap.test.ts(new, 25 tests)Visual regression tests covering:
cpp_str, snake_case, camelCase)tsconfig.json+package.jsonincludeupdated tolib/**/*.tsfilesupdated to includelib/CHANGELOG.md(new)Documents the fix with detailed technical breakdown.
README.mdTest Results
All 56 existing tests continue to pass + 25 new visual regression tests.
Performance Impact
wrapTextWithAnsi)containsBidi()is O(n) but typically returns falsequickly; only the small fraction of lines with RTL content take
the bidi path
Compatibility
Testing Locally
Screenshots
Before fix: text overflows the frame, code identifiers may appear reversed.
After fix: text wraps within the frame, code identifiers preserved.
(Screenshots available in the issue #23 description.)