feat(ai-scribe): Adding error handling for async operations

This commit is contained in:
dab246
2025-12-19 13:16:11 +07:00
committed by Dat H. Pham
parent b3dd6a9e85
commit a686b5d334
@@ -30,6 +30,7 @@ extension HandleAiScribeInComposerExtension on ComposerController {
} }
void insertTextInEditor(String text) async { void insertTextInEditor(String text) async {
try {
final htmlContent = StringConvert.convertTextContentToHtmlContent(text); final htmlContent = StringConvert.convertTextContentToHtmlContent(text);
if (PlatformInfo.isWeb) { if (PlatformInfo.isWeb) {
@@ -42,9 +43,13 @@ extension HandleAiScribeInComposerExtension on ComposerController {
} 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 {
try {
if (PlatformInfo.isWeb) { if (PlatformInfo.isWeb) {
await richTextWebController?.editorController.evaluateJavascriptWeb( await richTextWebController?.editorController.evaluateJavascriptWeb(
HtmlUtils.collapseSelectionToEnd.name, HtmlUtils.collapseSelectionToEnd.name,
@@ -56,25 +61,32 @@ extension HandleAiScribeInComposerExtension on ComposerController {
source: HtmlUtils.collapseSelectionToEnd.script, source: HtmlUtils.collapseSelectionToEnd.script,
); );
} }
} catch (e) {
logError('$runtimeType::collapseSelection:Exception = $e');
}
} }
void clearTextInEditor() { void clearTextInEditor() {
try {
if (PlatformInfo.isWeb) { if (PlatformInfo.isWeb) {
richTextWebController?.editorController.setText(''); richTextWebController?.editorController.setText('');
} else { } else {
richTextMobileTabletController?.htmlEditorApi?.setText(''); 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();