Extract method to convert html content to text content

Editor exposes html content (so with html tags) and we do not want to send them to AI backend
This commit is contained in:
Théo Poizat
2025-12-08 15:00:37 +01:00
committed by Dat H. Pham
parent 7d7ccaf874
commit 6dc58e2eb6
@@ -867,10 +867,7 @@ class ComposerController extends BaseController
}
}
Future<String> getTextOnlyContentInEditor() async {
try {
final htmlContent = await getContentInEditor();
String convertHtmlContentToTextContent(String htmlContent) {
String textContent = htmlContent.replaceAll(RegExp(r'<[^>]*>'), '');
textContent = textContent
@@ -882,6 +879,15 @@ class ComposerController extends BaseController
.replaceAll('&#39;', "'");
return textContent.trim();
}
Future<String> getTextOnlyContentInEditor() async {
try {
final htmlContent = await getContentInEditor();
String textContent = convertHtmlContentToTextContent(htmlContent);
return textContent;
} catch (e) {
logError('ComposerController::getTextOnlyContentInEditor:Exception = $e');
return '';
@@ -918,8 +924,6 @@ class ComposerController extends BaseController
);
}
void showAIScribeMenuForSelectedText(BuildContext context, {Offset? buttonPosition}) {
final selection = selectedText.value;
if (selection == null || selection.isEmpty) {
@@ -943,7 +947,7 @@ class ComposerController extends BaseController
if (textSelectionData.coordinates != null) {
textSelectionCoordinates.value = Offset(
textSelectionData.coordinates!.x,
textSelectionData.coordinates!.y + 6,
textSelectionData.coordinates!.y,
);
} else {
textSelectionCoordinates.value = null;