Improve text replace in Scribe

- Delete selection content before inserting
- Insert correct HTML
This commit is contained in:
Théo Poizat
2025-12-18 16:46:29 +01:00
committed by Dat H. Pham
parent 1a79445711
commit c78f6b8a76
2 changed files with 13 additions and 2 deletions
+6
View File
@@ -214,4 +214,10 @@ class StringConvert {
return textContent.trim(); return textContent.trim();
} }
static String convertTextContentToHtmlContent(String textContent) {
final htmlContent = textContent.replaceAll('\n', '<br>');
return '<div>$htmlContent</div>';
}
} }
@@ -29,10 +29,15 @@ extension HandleAiScribeInComposerExtension on ComposerController {
} }
} }
void insertTextInEditor(String text) { void insertTextInEditor(String text) async {
final htmlContent = text.replaceAll('\n', '<br>'); final htmlContent = StringConvert.convertTextContentToHtmlContent(text);
if (PlatformInfo.isWeb) { if (PlatformInfo.isWeb) {
await richTextWebController?.editorController.evaluateJavascriptWeb(
HtmlUtils.deleteSelectionContent.name,
hasReturnValue: false,
);
richTextWebController?.editorController.insertHtml(htmlContent); richTextWebController?.editorController.insertHtml(htmlContent);
} else { } else {
richTextMobileTabletController?.htmlEditorApi?.insertHtml(htmlContent); richTextMobileTabletController?.htmlEditorApi?.insertHtml(htmlContent);