fix(tui): use content majority for mixed bidi lines - #72508
Open
CodeinScrubs wants to merge 2 commits into
Open
Conversation
This was referenced Jul 27, 2026
2 tasks
CodeinScrubs
force-pushed
the
fix/tui-content-majority-bidi
branch
from
July 30, 2026 09:16
6a407a8 to
09c51fd
Compare
Contributor
|
Thanks for the focused renderer fix and regression coverage. The premise remains present on current No verified problems found in the two-file diff. It reuses the existing bidi-js dependency, preserves the no-op path for ASCII input, and adds targeted direction-policy tests. GitHub currently reports the branch as mergeable despite being behind main. Automated hermes-sweeper review. |
This was referenced Sep 2, 2026
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.
What does this PR do?
Hermes already applies
bidi-jsbefore Ink places terminal cells on Windows, Windows Terminal, WSL, and VS Code. The current call uses the Unicode first-strong (auto) paragraph base, so an English technical token at the start can force a Persian/Arabic-majority line onto the wrong base:This patch selects the base from all strong characters in the rendered line:
R/ALcharacters -> RTLLcharacters -> LTRIt uses Hermes's existing
bidi-jsdependency and adds no runtime dependency. Pure ASCII lines return the original array beforebidi-jsis initialized, preserving the common LTR fast path.Maintainer disclosure: I maintain the MIT-licensed BidiLens project. Its mixed-direction failure model and English-first/Persian-majority corpus case motivated this focused host patch. BidiLens is not added as a dependency because this implementation can use Hermes's existing renderer dependency and retain Hermes's current Node.js compatibility.
Related Issue
Advances the TUI work in #41454. The same first-strong failure class is reported for other Hermes surfaces in #51318 and #71613.
This PR also incorporates the regression-test commit from #15238 with its original author metadata, then adds the implementation and broader direction-policy tests.
Type of Change
Changes Made
ui-tui/packages/hermes-ink/src/ink/bidi.tsbidi-jsui-tui/packages/hermes-ink/src/ink/bidi.test.tsHow to Test
npm ci --workspace ui-tui --include-workspace-rootnpm test --workspace ui-tui -- packages/hermes-ink/src/ink/bidi.test.tsnpm run typecheck --workspace ui-tuinpm run build:ink --workspace ui-tuinpm exec --workspace ui-tui -- eslint packages/hermes-ink/src/ink/bidi.ts packages/hermes-ink/src/ink/bidi.test.tsnpx prettier --check ui-tui/packages/hermes-ink/src/ink/bidi.ts ui-tui/packages/hermes-ink/src/ink/bidi.test.tsFresh local results:
git diff --check: passedI also ran
npm run check --workspace ui-tui. Build and typecheck passed, and 1,385 tests passed. Eight unrelated Windows/environment-sensitive tests failed interminalSetup.test.ts,terminalParity.test.ts, andeditor.test.ts; the command registry setup also reports the local Python environment missingyaml. I am not claiming the complete local suite is green.Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests pass — not run; this patch only changes the TypeScript TUI renderer, and the relevant TUI checks are listed aboveDocumentation & Housekeeping
docs/, docstrings) — N/A; behavior and constraints are documented inline and in testscli-config.yaml.exampleif I added/changed config keys — N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — N/AScreenshots / Logs
For the English-first Persian-majority fixture, the current first-strong path produces this visual-cell order:
The content-majority RTL base produces:
The patch remains intentionally scoped to Hermes's current software-bidi path and the scripts handled by its existing
bidi-jsversion. Terminal font shaping and supplementary-plane limitations in that dependency are outside this PR.