dankito / RichTextEditor

Rich text WYSIWYG editor for Android and JavaFX
Apache License 2.0
92 stars 36 forks source link

Max length #61

Open fongfuse opened 3 years ago

fongfuse commented 3 years ago

How to set Max length in RichTextEditor

dankito commented 3 years ago

Hi @fongfuse,

sorry, but there's no such thing as max length in RichTextEditor. But you can quite easily implement this yourself by adding a HtmlChangedListener:

        editor.addHtmlChangedListener(new HtmlChangedListener() {
            @Override
            public void htmlChangedAsync(@NotNull String html) {
                if (html.length() > MAX_LENGTH) {
                    editor.setHtml(html.substring(0, MAX_LENGTH));
                }
            }
        });

Does this help you any further?