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();
}
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) {
final htmlContent = text.replaceAll('\n', '<br>');
void insertTextInEditor(String text) async {
final htmlContent = StringConvert.convertTextContentToHtmlContent(text);
if (PlatformInfo.isWeb) {
await richTextWebController?.editorController.evaluateJavascriptWeb(
HtmlUtils.deleteSelectionContent.name,
hasReturnValue: false,
);
richTextWebController?.editorController.insertHtml(htmlContent);
} else {
richTextMobileTabletController?.htmlEditorApi?.insertHtml(htmlContent);