Repository navigation
editor: add configurable text direction for RTL language support (#11770) - #318214
DisturbedSage (DisturbedSage5840C) wants to merge 4 commits into
Conversation
Adds a new `editor.textDirection` setting (`ltr`, `rtl`, `auto`) that controls the rendered direction of editor lines and input elements, providing a foundation for right-to-left language support (issue microsoft#11770). - `editorOptions.ts`: register `EditorTextDirection` type and `textDirection` option with `ltr`/`rtl`/`auto` values - `viewModelImpl.ts`: compute per-line direction from config when no decoration override is present; `auto` uses a first-strong-character heuristic (RTL chars vs LTR chars) - `textAreaEditContext.ts`: sync the hidden `<textarea>` and cover element `dir` attribute on init, config change, selection change, and render so IME composition respects the active text direction - `nativeEditContext.ts`: apply the same `dir` sync to the EditContext DOM node and IME textarea so native input APIs follow text direction - `workbench.contribution.ts`: add `workbench.textDirection` setting (`ltr`/`rtl`) that controls the overall workbench UI direction - `workbench.ts`: apply `dir` attribute to the main container on startup and whenever `workbench.textDirection` changes - `auxiliaryWindowService.ts`: propagate `dir` attribute to auxiliary windows so floating editors and panels mirror the main window direction - `monaco.d.ts`: export `EditorTextDirection` type, add `textDirection` option to `IEditorOptions`, update `EditorOption` enum values, and add `textDirection` entry to `EditorOptions` Fixes microsoft#11770
|
@microsoft-github-bot-services agree |
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds configurable UI/editor text direction support (LTR/RTL, with editor auto-detection) and propagates direction changes to auxiliary windows and edit contexts.
Changes:
- Introduces
workbench.textDirectionand applies it to the workbench container viadir. - Adds editor option
textDirection(ltr/rtl/auto) and uses it in line direction resolution. - Updates textarea/native edit contexts (and auxiliary windows) to sync DOM
dirattributes.
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| src/vs/workbench/services/auxiliaryWindow/browser/auxiliaryWindowService.ts | Syncs dir attribute to auxiliary window container. |
| src/vs/workbench/browser/workbench.ts | Applies workbench.textDirection to the main container on config changes and startup. |
| src/vs/workbench/browser/workbench.contribution.ts | Registers new workbench.textDirection configuration schema. |
| src/vs/monaco.d.ts | Exposes new textDirection editor option typing and enum member. |
| src/vs/editor/common/viewModel/viewModelImpl.ts | Adds configured/auto direction logic when no decorations force direction. |
| src/vs/editor/common/config/editorOptions.ts | Registers editor option textDirection and its type. |
| src/vs/editor/browser/controller/editContext/textArea/textAreaEditContext.ts | Updates textarea/covers dir based on current line direction. |
| src/vs/editor/browser/controller/editContext/native/nativeEditContext.ts | Updates native edit context DOM dir based on current line direction. |
- Use \p{L}/u (all Unicode letters) instead of a hand-rolled Latin-only
regex for strong-LTR detection; simplify _getAutoTextDirection to a
single left-to-right scan that returns on the first strong character
(RTL check before LTR, matching the Unicode first-strong algorithm)
- Validate workbench.textDirection config value by reading as string
and clamping to 'ltr'|'rtl' before applying, so manually edited
settings.json cannot produce an invalid dir attribute
- Cache the computed text direction in TextAreaEditContext indexed by
line number; only recompute on line change or forced recompute
(config change); avoids redundant getTextDirection() calls on every
render frame
- Same caching applied to NativeEditContext._updateTextDirection();
_updateDomAttributes() passes forceRecompute=true so a settings
change always picks up the new value
|
@microsoft-github-policy-service agree |
|
Hi Michael Lively (@Yoyokrazy)! Just wanted to give a gentle ping since you were assigned to this PR. Happy to make any changes needed to help move this forward. Thanks for your time! |
|
Hi Michael Lively (@Yoyokrazy)! Sending a second gentle ping on this one. Since the initial Copilot review I pushed a follow-up commit that addressed all 8 comments — they're now showing as "Outdated" (the orange badges) because the code they pointed to has changed:
The branch is also synced with the latest main. Happy to make any further changes you'd like. Thanks for your time! |
Summary
Fixes #11770 — Support for RTL languages.
This is the foundational phase of RTL support: a configurable
editor.textDirectionsetting that plumbs through the view model, rendering pipeline, and input layer so editors respect right-to-left text direction.What changed
editor.textDirectionsetting (ltr|rtl|auto, defaultltr) registered ineditorOptions.tsand exported inmonaco.d.tsviewModelImpl.ts): per-line direction falls back to the configured setting when no decoration override is present;automode uses a first-strong-character heuristic (first RTL char vs first LTR char wins)textAreaEditContext.ts): hidden<textarea>and cover element get theirdirattribute synced on init, config change, selection change, and each render — keeps IME composition aligned with text directionnativeEditContext.ts): samedirsync applied to thediv[contenteditable]DOM node and IME textarea so the EditContext API path also respects RTLworkbench.contribution.ts,workbench.ts): addsworkbench.textDirectionsetting (ltr|rtl) that sets thedirattribute on the main workbench container, allowing the overall UI chrome to mirror for RTL localesauxiliaryWindowService.ts):dirattribute is now tracked alongsideclassso floating editors/panels inherit the correct directionmonaco.d.ts: all public API surfaces updated (new type, updated enum values, newEditorOptionsentry)Test plan
"editor.textDirection": "rtl"in settings — lines should render right-to-left"editor.textDirection": "auto"and type Arabic/Hebrew text — the line's direction should switch to RTL automatically"workbench.textDirection": "rtl"— verify tabs, sidebar, and panel layout mirror correctlydirattribute from the main window./scripts/test.sh --grep ViewModelTextDirectionto verify the view model direction unit tests pass