Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Proposal] Add support for automatically switching text input to RTL or LTR based on first character typed #91738

Open
sm2017 opened this issue Oct 13, 2021 · 9 comments
Labels
a: internationalization Supporting other languages or locales. (aka i18n) a: text input Entering text in a text field or keyboard related problems c: new feature Nothing broken; request for a new capability c: proposal A detailed proposal for a change to Flutter framework flutter/packages/flutter repository. See also f: labels. P3 Issues that are less important to the Flutter project team-framework Owned by Framework team triaged-framework Triaged by Framework team

Comments

@sm2017
Copy link

sm2017 commented Oct 13, 2021

Use case

In multilingual text fields, Bidirectional text input is automatically recognised. For example, typing ب as the first character in Whatsapp places the cursor the right side and typing b as the first, places the cursor at the left side. That is it automatically detects the language and makes the text input appropriate, whether it is an RTL or LTR language.

Proposal

I think flutter must detect bidirectional text input out of the box, no matter what is the current Directionality.of(context). The same behaviour stated above should be exhibited in flutter textfields.

@sm2017
Copy link
Author

sm2017 commented Oct 13, 2021

Not only TextField, but also Text must detect bidirectional text out of the box, I think having a bool property like matchContentDirection with default value as true is awesome, I'm not sure may be TextAlign.auto as default text direction is better
Detecting bidirectional text must be added to TextField itself and all text in it like hint , helper, error

@danagbemava-nc danagbemava-nc added the in triage Presently being triaged by the triage team label Oct 13, 2021
@danagbemava-nc
Copy link
Member

In multilingual text input, usually it detect Bidirectional text

Hi @sm2017, I'm not particularly familiar with Bidirectional text input, can you expand more on this?

@danagbemava-nc danagbemava-nc added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Oct 13, 2021
@sm2017
Copy link
Author

sm2017 commented Oct 13, 2021

See https://en.m.wikipedia.org/wiki/Bidirectional_text

There is a bidi class in flutter https://api.flutter.dev/flutter/intl/Bidi-class.html

It is impossible to implement my feature request in application layer, because we have dependencies that has text field or text widget

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Oct 13, 2021
@danagbemava-nc
Copy link
Member

@sm2017, my question was poorly phrased, what I meant was can you expand a bit more on this statement you made earlier?

In multilingual text input, usually it detect Bidirectional text

@danagbemava-nc danagbemava-nc added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Oct 14, 2021
@sm2017
Copy link
Author

sm2017 commented Oct 15, 2021

Let me describe default behavior of text input in Android os, Chrome, Whatsapp and ...

In your Chrome search bar, try to type ب , feel free to copy and paste it, you can see the direction of text is detected as LRT, AFAIK it's a common behavior in most operation systems and applications

It's Bidirectional text input as it's context-aware

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Oct 15, 2021
@danagbemava-nc danagbemava-nc changed the title Bidirectional text field [Proposal] Add support for automatically switching text input to RTL or LTR based on first character typed Oct 15, 2021
@danagbemava-nc danagbemava-nc added a: internationalization Supporting other languages or locales. (aka i18n) a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. passed first triage c: proposal A detailed proposal for a change to Flutter c: new feature Nothing broken; request for a new capability and removed in triage Presently being triaged by the triage team labels Oct 15, 2021
@danagbemava-nc
Copy link
Member

danagbemava-nc commented Oct 15, 2021

@sm2017, thanks for the insight.
I have updated the proposal to make it clearer.

@TarekkMA
Copy link
Contributor

It might be a good idea to add a new value called auto similar to the web.

For reference here are the docs on dir.
https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/dir

@goderbauer goderbauer added the P3 Issues that are less important to the Flutter project label Feb 23, 2022
@xmine64
Copy link

xmine64 commented Apr 20, 2022

I need this, it's so useful. I added some code to onChange property of TextFields in my app to set text direction based on content.

@LongCatIsLooong
Copy link
Contributor

@goderbauer This seems technically feasible (https://unicode-org.github.io/icu-docs/apidoc/dev/icu4c/ubidi_8h.html#a165ae276878c7a54fd8b067db0d12f40).

Does it make sense to add this to TextPainter? I guess for WidgetSpans we'll need a new low-level API that gives us the real writing direction of a paragraph, before we can build those inline widgets with the correct writing directions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: internationalization Supporting other languages or locales. (aka i18n) a: text input Entering text in a text field or keyboard related problems c: new feature Nothing broken; request for a new capability c: proposal A detailed proposal for a change to Flutter framework flutter/packages/flutter repository. See also f: labels. P3 Issues that are less important to the Flutter project team-framework Owned by Framework team triaged-framework Triaged by Framework team
Projects
None yet
Development

No branches or pull requests

7 participants