feat(ai-scribe): Adding error handling for async operations
This commit is contained in:
+37
-25
@@ -30,51 +30,63 @@ extension HandleAiScribeInComposerExtension on ComposerController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void insertTextInEditor(String text) async {
|
void insertTextInEditor(String text) async {
|
||||||
final htmlContent = StringConvert.convertTextContentToHtmlContent(text);
|
try {
|
||||||
|
final htmlContent = StringConvert.convertTextContentToHtmlContent(text);
|
||||||
|
|
||||||
if (PlatformInfo.isWeb) {
|
if (PlatformInfo.isWeb) {
|
||||||
await richTextWebController?.editorController.evaluateJavascriptWeb(
|
await richTextWebController?.editorController.evaluateJavascriptWeb(
|
||||||
HtmlUtils.deleteSelectionContent.name,
|
HtmlUtils.deleteSelectionContent.name,
|
||||||
hasReturnValue: false,
|
hasReturnValue: false,
|
||||||
);
|
);
|
||||||
|
|
||||||
richTextWebController?.editorController.insertHtml(htmlContent);
|
richTextWebController?.editorController.insertHtml(htmlContent);
|
||||||
} else {
|
} else {
|
||||||
richTextMobileTabletController?.htmlEditorApi?.insertHtml(htmlContent);
|
richTextMobileTabletController?.htmlEditorApi?.insertHtml(htmlContent);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
logError('$runtimeType::insertTextInEditor:Exception = $e');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> collapseSelection() async {
|
Future<void> collapseSelection() async {
|
||||||
if (PlatformInfo.isWeb) {
|
try {
|
||||||
await richTextWebController?.editorController.evaluateJavascriptWeb(
|
if (PlatformInfo.isWeb) {
|
||||||
HtmlUtils.collapseSelectionToEnd.name,
|
await richTextWebController?.editorController.evaluateJavascriptWeb(
|
||||||
hasReturnValue: false,
|
HtmlUtils.collapseSelectionToEnd.name,
|
||||||
);
|
hasReturnValue: false,
|
||||||
} else {
|
);
|
||||||
await richTextMobileTabletController?.htmlEditorApi?.webViewController
|
} else {
|
||||||
.evaluateJavascript(
|
await richTextMobileTabletController?.htmlEditorApi?.webViewController
|
||||||
source: HtmlUtils.collapseSelectionToEnd.script,
|
.evaluateJavascript(
|
||||||
);
|
source: HtmlUtils.collapseSelectionToEnd.script,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
logError('$runtimeType::collapseSelection:Exception = $e');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearTextInEditor() {
|
void clearTextInEditor() {
|
||||||
if (PlatformInfo.isWeb) {
|
try {
|
||||||
richTextWebController?.editorController.setText('');
|
if (PlatformInfo.isWeb) {
|
||||||
} else {
|
richTextWebController?.editorController.setText('');
|
||||||
richTextMobileTabletController?.htmlEditorApi?.setText('');
|
} else {
|
||||||
|
richTextMobileTabletController?.htmlEditorApi?.setText('');
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
logError('$runtimeType::clearTextInEditor:Exception = $e');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure we only insert at cursor position by collapsing selection before inserting
|
// Ensure we only insert at cursor position by collapsing selection before inserting
|
||||||
void onInsertTextCallback(String text) async {
|
Future<void> onInsertTextCallback(String text) async {
|
||||||
await collapseSelection();
|
await collapseSelection();
|
||||||
|
|
||||||
insertTextInEditor(text);
|
insertTextInEditor(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there is a selection, it will replace the selection, else it will replace everything
|
// If there is a selection, it will replace the selection, else it will replace everything
|
||||||
void onReplaceTextCallback(String text) async {
|
void onReplaceTextCallback(String text) {
|
||||||
final selection = editorTextSelection.value?.selectedText;
|
final selection = editorTextSelection.value?.selectedText;
|
||||||
if (selection == null || selection.isEmpty) {
|
if (selection == null || selection.isEmpty) {
|
||||||
clearTextInEditor();
|
clearTextInEditor();
|
||||||
|
|||||||
Reference in New Issue
Block a user