facebook / facebook/lexical

Full bidirectional (RTL) support

Open
#2,610 18 comments 7 reactions 0 assignees View on GitHub
core enhancement text direction
Dominant language
TypeScript
Stars
23.9k
Forks
2.2k
Avg merge
1d 16h
Merged PRs (30d)
61

Description

The following is a short overview of bi-directional editing surfaces and my suggestion for improving Lexical’s implementation. _(Continued from the [Discord discussion](https://discord.com/channels/953974421008293909/955972012541628456/993985520747155476))_

### Overview
Modern editing surfaces’ default behavior today is to support bi-directional content by setting the direction based on the first letter’s language. This can be seen in the current Lexical implementation, _Apple Notes_, _Gmail_, and _Google Docs_:

https://user-images.githubusercontent.com/1909713/177728347-054678d1-cf3e-47d5-817e-c5041ff144ef.mp4

One implementation detail crucial for longer-form and complex content (like a letter or an article) is maintaining the previous paragraph setting if the user manually sets it. _Microsoft Office Word_ gets this correctly:

https://user-images.githubusercontent.com/1909713/177722676-d603b861-daad-42b4-8378-f053bc455fa9.mp4

_The recordings demonstrate Hebrew, but the behavior is similar in Arabic._

### Implementation Suggestions

The following are my suggestions for scalable bi-directional support in Lexical:
1. Maintain the current dynamic evaluation of direction as the default behavior.
2. Add support for manually toggling/setting the node’s direction.
3. If a node has a `direction` manually set, it should be respected. (When parsing a serialized editor state, the current implementation dynamically evaluates the content, disregarding the provided configuration.)
4. One (or both) of the following will allow composing more complex content (letter/article) without constant friction:
4.1. If the root node’s direction is _manually_ set, it should be the default direction for child nodes.
4.2. When creating a following paragraph, if the previous paragraph has a manual direction set, it should be copied into the next paragraph.

Contributor guide

Open the contributing guide

Research direction

The issue does not name files or tests. Start by locating Lexical’s existing dynamic direction evaluation and serialized editor-state parsing, then trace how root and paragraph directions are created and preserved. Done means manually set directions are supported, survive parsing, and follow the specified root and next-paragraph behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend, internationalization
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.