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');
|
||||
|
||||
+12
@@ -148,6 +148,14 @@ extension HandleAiScribeInComposerExtension on ComposerController {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> ensureMobileEditorFocused() async {
|
||||
try {
|
||||
await richTextMobileTabletController?.focus();
|
||||
} catch (e) {
|
||||
logError('$runtimeType::ensureMobileEditorFocused:Exception = $e');
|
||||
}
|
||||
}
|
||||
|
||||
void clearTextInEditor() {
|
||||
try {
|
||||
if (PlatformInfo.isWeb) {
|
||||
@@ -207,6 +215,10 @@ extension HandleAiScribeInComposerExtension on ComposerController {
|
||||
AiScribeSuggestionActions action,
|
||||
String suggestionText,
|
||||
) async {
|
||||
if (PlatformInfo.isMobile) {
|
||||
await ensureMobileEditorFocused();
|
||||
}
|
||||
|
||||
switch (action) {
|
||||
case AiScribeSuggestionActions.replace:
|
||||
await onReplaceTextCallback(suggestionText);
|
||||
|
||||
Reference in New Issue
Block a user