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

Text direction by default #49

Closed
imanpr opened this issue May 22, 2021 · 3 comments
Closed

Text direction by default #49

imanpr opened this issue May 22, 2021 · 3 comments
Labels
question Further information is requested

Comments

@imanpr
Copy link

imanpr commented May 22, 2021

Type question here.
how can change direction to RTL by default?
and how can change language on values?
thanks

@imanpr imanpr added the question Further information is requested label May 22, 2021
@imanpr
Copy link
Author

imanpr commented May 22, 2021

i find this method
controller.changeTextDirection('rtl')

but its not working

@tneotia
Copy link
Owner

tneotia commented May 22, 2021

That method only works on Flutter Web, and should only be used internally (the documentation says this as well). If you see the implementation of text direction, I have:

                if (kIsWeb) {
                  widget.controller
                      .changeTextDirection(index == 0 ? 'ltr' : 'rtl');
                } else {
                  await widget.controller.editorController!
                      .evaluateJavascript(source: """
                  var s=document.getSelection();			
                  if(s==''){
                      document.execCommand("insertHTML", false, "<p dir='${index == 0 ? "ltr" : "rtl"}'></p>");
                  }else{
                      document.execCommand("insertHTML", false, "<div dir='${index == 0 ? "ltr" : "rtl"}'>"+ document.getSelection()+"</div>");
                  }
                """);
                }

So on mobile there is different code than web.

To change the text direction permanently on startup, use

HtmlEditor(
   callbacks: Callbacks(
      onInit: () {
         controller.editorController!.evaluateJavascript(source: "\$('div.note-editable').attr('dir', 'rtl');"); 
      }
   )
)

Hope it helps.

@tneotia
Copy link
Owner

tneotia commented Jun 2, 2021

Closing this issue for now, let me know if you have further questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants