TF-1878 Fix font family not changed correctly in composer

(cherry picked from commit a4c72a79abf429aa2938c8218308f1ac16f89d76)
This commit is contained in:
dab246
2023-06-16 12:45:26 +07:00
committed by Dat H. Pham
parent f589b11637
commit 68145165be
3 changed files with 73 additions and 14 deletions
@@ -47,8 +47,16 @@ class RichTextWebController extends BaseRichTextController {
});
}
void onEditorSettingsChange(EditorSettings settings) async {
log('RichTextWebController::onEditorSettingsChange():foregroundColor: ${settings.foregroundColor} | backgroundColor: ${settings.backgroundColor}');
void onEditorSettingsChange(EditorSettings settings) {
_updateTextStyle(settings);
_updateFontName(settings);
_updateTextColor(settings);
_updateBackgroundTextColor(settings);
_updateOrderList(settings);
_updateParagraph(settings);
}
void _updateTextStyle(EditorSettings settings) {
listTextStyleApply.clear();
if (settings.isBold) {
@@ -67,11 +75,35 @@ class RichTextWebController extends BaseRichTextController {
listTextStyleApply.add(RichTextStyleType.strikeThrough);
}
log('RichTextWebController::onEditorSettingsChange(): $listTextStyleApply');
log('RichTextWebController::_updateTextStyle(): $listTextStyleApply');
}
void _updateFontName(EditorSettings settings) {
log('RichTextWebController::_updateFontName():fontName: ${settings.fontName}');
final matchedFontName = FontNameType.values.firstWhereOrNull((fontName) => fontName.value == settings.fontName);
log('RichTextWebController::_updateFontName():matchedFontName: $matchedFontName');
if (matchedFontName != null) {
selectedFontName.value = matchedFontName;
}
}
void _updateTextColor(EditorSettings settings) {
selectedTextColor.value = settings.foregroundColor;
selectedTextBackgroundColor.value = settings.backgroundColor;
}
void _updateBackgroundTextColor(EditorSettings settings) {
selectedTextBackgroundColor.value = settings.backgroundColor;
}
void _updateOrderList(EditorSettings settings) {
if (settings.isOl) {
selectedOrderList.value = OrderListType.numberedList;
} else if (settings.isUl) {
selectedOrderList.value = OrderListType.bulletedList;
}
}
void _updateParagraph(EditorSettings settings) {
if (settings.isAlignCenter) {
selectedParagraph.value = ParagraphType.alignCenter;
} else if (settings.isAlignJustify) {
@@ -81,12 +113,6 @@ class RichTextWebController extends BaseRichTextController {
} else if (settings.isAlignRight) {
selectedParagraph.value = ParagraphType.alignRight;
}
if (settings.isOl) {
selectedOrderList.value = OrderListType.numberedList;
} else if (settings.isUl) {
selectedOrderList.value = OrderListType.bulletedList;
}
}
void applyRichTextStyle(BuildContext context, RichTextStyleType textStyleType) {
@@ -157,8 +183,8 @@ class RichTextWebController extends BaseRichTextController {
final fontSelected = newFont ?? FontNameType.sansSerif;
selectedFontName.value = fontSelected;
editorController.execCommand(
RichTextStyleType.fontName.commandAction,
argument: fontSelected.fontFamily);
RichTextStyleType.fontName.commandAction,
argument: fontSelected.value);
editorController.setFocus();
}