diff --git a/README.md b/README.md index cb0ee25..358147f 100644 --- a/README.md +++ b/README.md @@ -131,6 +131,15 @@ editor.apply { To safely use your own WebViewClient instance with the editor, you have to call the RichHtmlEditorWebView's `notifyPageHasLoaded()` inside your custom WebViewClient's `onPageFinished()` callback. +### Activate/Deactivate spellcheck + +Spellcheck is activated by default but if you don't want to have any spellcheck done on the editor content, +you can do that by doing so. + +```kt +editor.withSpellCheck(false) +``` + ### More advanced features For more advanced features, take a look at the [sample project](sample) or diff --git a/rich-html-editor/src/main/java/com/infomaniak/lib/richhtmleditor/RichHtmlEditorWebView.kt b/rich-html-editor/src/main/java/com/infomaniak/lib/richhtmleditor/RichHtmlEditorWebView.kt index 11a056a..d346d45 100644 --- a/rich-html-editor/src/main/java/com/infomaniak/lib/richhtmleditor/RichHtmlEditorWebView.kt +++ b/rich-html-editor/src/main/java/com/infomaniak/lib/richhtmleditor/RichHtmlEditorWebView.kt @@ -40,6 +40,7 @@ import com.infomaniak.lib.richhtmleditor.executor.KeyboardOpener import com.infomaniak.lib.richhtmleditor.executor.ScriptCssInjector import com.infomaniak.lib.richhtmleditor.executor.ScriptCssInjector.CodeInjection import com.infomaniak.lib.richhtmleditor.executor.ScriptCssInjector.CodeInjection.InjectionType +import com.infomaniak.lib.richhtmleditor.executor.SpellCheckHtmlSetter import com.infomaniak.lib.richhtmleditor.executor.StateSubscriber import kotlinx.coroutines.CoroutineName import kotlinx.coroutines.CoroutineScope @@ -83,6 +84,7 @@ class RichHtmlEditorWebView @JvmOverloads constructor( private val documentInitializer = DocumentInitializer() private val stateSubscriber = StateSubscriber(this) private val htmlSetter = HtmlSetter(this) + private val spellCheckHtmlSetter = SpellCheckHtmlSetter(this) private val jsExecutor = JsExecutor(this) private val scriptCssInjector = ScriptCssInjector(this) private val keyboardOpener = KeyboardOpener(this) @@ -134,6 +136,8 @@ class RichHtmlEditorWebView @JvmOverloads constructor( webViewClient = RichHtmlEditorWebViewClient(::notifyPageHasLoaded) + withSpellCheck(true) + addJavascriptInterface(jsBridge, "editor") stateSubscriber.executeWhenDomIsLoaded(null) @@ -171,6 +175,11 @@ class RichHtmlEditorWebView @JvmOverloads constructor( */ fun addCss(css: String) = scriptCssInjector.executeWhenDomIsLoaded(CodeInjection(InjectionType.CSS, css)) + /** + * Injects a custom attribute to the editor div to activate/deactivate spellchecking. By default, spellcheck is activated. + */ + fun withSpellCheck(enable: Boolean) = spellCheckHtmlSetter.executeWhenDomIsLoaded(enable) + /** * Injects a custom script tag into the `
` of the editor template. * @@ -224,6 +233,7 @@ class RichHtmlEditorWebView @JvmOverloads constructor( stateSubscriber.notifyDomLoaded() htmlSetter.notifyDomLoaded() + spellCheckHtmlSetter.notifyDomLoaded() jsExecutor.notifyDomLoaded() scriptCssInjector.notifyDomLoaded() keyboardOpener.notifyDomLoaded() @@ -339,6 +349,9 @@ class RichHtmlEditorWebView @JvmOverloads constructor( } companion object { + // The id of this HTML tag is shared across multiple files and needs to remain the same + const val EDITOR_ID = "editor" + private const val KEYBOARD_SHOULD_REOPEN_KEY = "keyboardShouldReopen" private const val SUPER_STATE_KEY = "superState" } diff --git a/rich-html-editor/src/main/java/com/infomaniak/lib/richhtmleditor/executor/HtmlSetter.kt b/rich-html-editor/src/main/java/com/infomaniak/lib/richhtmleditor/executor/HtmlSetter.kt index 300075a..d3d8191 100644 --- a/rich-html-editor/src/main/java/com/infomaniak/lib/richhtmleditor/executor/HtmlSetter.kt +++ b/rich-html-editor/src/main/java/com/infomaniak/lib/richhtmleditor/executor/HtmlSetter.kt @@ -18,6 +18,7 @@ package com.infomaniak.lib.richhtmleditor.executor import android.webkit.WebView +import com.infomaniak.lib.richhtmleditor.RichHtmlEditorWebView.Companion.EDITOR_ID import com.infomaniak.lib.richhtmleditor.looselyEscapeAsStringLiteralForJs internal class HtmlSetter(private val webView: WebView) : JsLifecycleAwareExecutor