Skip to content

editor: add configurable text direction for RTL language support (#11770) - #318214

Open
DisturbedSage (DisturbedSage5840C) wants to merge 4 commits into
microsoft:mainfrom
DisturbedSage5840C:feat/rtl-language-support
Open

DisturbedSage (DisturbedSage5840C) wants to merge 4 commits into
microsoft:mainfrom
DisturbedSage5840C:feat/rtl-language-support

Conversation

@DisturbedSage5840C

@DisturbedSage5840C DisturbedSage (DisturbedSage5840C) commented May 25, 2026 •

Copy link
Copy Markdown

Summary

Fixes #11770 — Support for RTL languages.

This is the foundational phase of RTL support: a configurable editor.textDirection setting that plumbs through the view model, rendering pipeline, and input layer so editors respect right-to-left text direction.

What changed

  • editor.textDirection setting (ltr | rtl | auto, default ltr) registered in editorOptions.ts and exported in monaco.d.ts
  • View model (viewModelImpl.ts): per-line direction falls back to the configured setting when no decoration override is present; auto mode uses a first-strong-character heuristic (first RTL char vs first LTR char wins)
  • Textarea input (textAreaEditContext.ts): hidden <textarea> and cover element get their dir attribute synced on init, config change, selection change, and each render — keeps IME composition aligned with text direction
  • Native EditContext (nativeEditContext.ts): same dir sync applied to the div[contenteditable] DOM node and IME textarea so the EditContext API path also respects RTL
  • Workbench UI (workbench.contribution.ts, workbench.ts): adds workbench.textDirection setting (ltr | rtl) that sets the dir attribute on the main workbench container, allowing the overall UI chrome to mirror for RTL locales
  • Auxiliary windows (auxiliaryWindowService.ts): dir attribute is now tracked alongside class so floating editors/panels inherit the correct direction
  • monaco.d.ts: all public API surfaces updated (new type, updated enum values, new EditorOptions entry)

Test plan

  • Open an editor and set "editor.textDirection": "rtl" in settings — lines should render right-to-left
  • Set "editor.textDirection": "auto" and type Arabic/Hebrew text — the line's direction should switch to RTL automatically
  • Verify IME composition (Korean, Japanese, Arabic) works without direction artifacts in both textarea and native EditContext paths
  • Set "workbench.textDirection": "rtl" — verify tabs, sidebar, and panel layout mirror correctly
  • Open an auxiliary window (e.g. detached editor) — confirm it inherits the dir attribute from the main window
  • Run ./scripts/test.sh --grep ViewModelTextDirection to verify the view model direction unit tests pass

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
Copilot AI review requested due to automatic review settings May 25, 2026 14:49
@DisturbedSage5840C

Copy link
Copy Markdown
Author

@microsoft-github-bot-services agree

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.textDirection and applies it to the workbench container via dir.
  • 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 dir attributes.

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.

Comment thread src/vs/workbench/browser/workbench.ts Resolved
Comment thread src/vs/workbench/browser/workbench.ts Resolved
- 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
@DisturbedSage5840C

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@DisturbedSage5840C

Copy link
Copy Markdown
Author

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!

@DisturbedSage5840C

Copy link
Copy Markdown
Author

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:

  • STRONG_LTR_REGEX → widened from Latin-only to /\p{L}/u to cover all Unicode strong-LTR scripts (Greek, Cyrillic, etc.)
  • Render caching → both the textarea and native edit contexts now cache the last evaluated line number, so getTextDirection() is only called when the cursor actually moves to a different line or when the textDirection option changes
  • Dir coercion → workbench reads the setting as string and clamps to 'rtl' | 'ltr', so a manually-edited invalid value can never reach setAttribute

The branch is also synced with the latest main. Happy to make any further changes you'd like. Thanks for your time!

This branch has not been deployed

No deployments
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.

Support for RTL languages

4 participants