Ensure editor is focused before calling insert HTML
enough_html_editor uses execCommand to insert HTML. However execCommand only works if the contenteditable element is focused. So inserting or replacing Scribe result do not work if the user did not click before in the composer. Here we manually focus the contenteditable element to fix this before inserting content.
This commit is contained in:
@@ -19,6 +19,14 @@ class RichTextMobileTabletController extends GetxController {
|
||||
|
||||
Future<bool> get isEditorFocused async => await htmlEditorApi?.hasFocus() ?? false;
|
||||
|
||||
Future<void> focus() async {
|
||||
try {
|
||||
await htmlEditorApi?.webViewController.evaluateJavascript(source: "document.getElementById('editor').focus();");
|
||||
} catch (e) {
|
||||
logWarning('RichTextMobileTabletController::focus:Exception: $e');
|
||||
}
|
||||
}
|
||||
|
||||
void insertImage(InlineImage inlineImage) async {
|
||||
final isFocused = await isEditorFocused;
|
||||
log('RichTextMobileTabletController::insertImage: isEditorFocused = $isFocused');
|
||||
|
||||
Reference in New Issue
Block a user