tneotia/html-editor-enhanced

[QUESTION] How to change the default font family in the Editor?

sigmapie8 opened this issue · 6 comments

I want to remove the font-family drop down and set one default font. How can I do that?

To set the default font I think you can do:

HtmlEditor(
   callbacks: Callbacks(
      onInit: () {
         controller.execCommand('fontName', argument: "font_name_here");
      }
   )
)

Your font name has to be inserted in the exact same way it would be in HTML, for example sans-serif or Times New Roman.

I haven't tested this but I think it should work, and you can use defaultToolbarButtons to remove the font dropdown. If it doesn't work please post the code you tried and I will try to make a working solution tomorrow. Thanks!

Hope this helped you, let me know if you have further questions.

@tneotia Just bringing something to your attention here. Commit - 9cbd9f3 links to this issue as the recommended way to set the default font. However, as per your reply in the issue #125 , execCommand should be used via onFocus callback and not onInit as suggested in this issue.

Thanks for bringing to my attention, that was a mistake on my part. Fixing right now :)

I try to set fontName like you, but I can't change the default font family in the editor. (I don't use defaultToolbarButtons.)
@tneotia

To set the default font I think you can do:

HtmlEditor(
   callbacks: Callbacks(
      onInit: () {
         controller.execCommand('fontName', argument: "font_name_here");
      }
   )
)

Your font name has to be inserted in the exact same way it would be in HTML, for example sans-serif or Times New Roman.

I haven't tested this but I think it should work, and you can use defaultToolbarButtons to remove the font dropdown. If it doesn't work please post the code you tried and I will try to make a working solution tomorrow. Thanks!

I try to set fontName like you, but I can't change the default font family in the editor. (I don't use defaultToolbarButtons.) @tneotia

To set the default font I think you can do:

HtmlEditor(
   callbacks: Callbacks(
      onInit: () {
         controller.execCommand('fontName', argument: "font_name_here");
      }
   )
)

Your font name has to be inserted in the exact same way it would be in HTML, for example sans-serif or Times New Roman.
I haven't tested this but I think it should work, and you can use defaultToolbarButtons to remove the font dropdown. If it doesn't work please post the code you tried and I will try to make a working solution tomorrow. Thanks!

sama for me