tneotia/html-editor-enhanced

Text direction by default

imanpr opened this issue · 3 comments

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

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

but its not working

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.

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