dankito / RichTextEditor

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

Is it possible to add custom commands? #50

Closed marius-zilinskas closed 4 years ago

marius-zilinskas commented 4 years ago

I would like to add custom functionality - add code block selection formatting. Is it possible to implement custom fuctions? Maybe you have an example? Thanks

dankito commented 4 years ago

In general of course it is possible to implement custom functionality, though depending on your use case it might is quite hard to implement.

You simply have to derive your class from ToolbarCommand (or one of its child classes) and implement the method executeCommand(JavaScriptExecutorBase).

In this method call executeEditorJavaScriptFunction(String javaScript, null) on JavaScriptExecutorBase to implement your custom functionality.

How hard it is to implement your use case depends on how hard it it to implement it in JavaScript as RichTextEditor under the hood uses ContentEditable feature of HTML 5.

May these two links provide you a starting point: https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Editable_content https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand

Or take a look at my editor JavaScript: https://github.com/dankito/RichTextEditor/blob/master/RichTextEditorCommon/src/main/resources/editor/rich_text_editor.js