TF-1851,1852 Fix selected "rich text menu" do not match current text status

(cherry picked from commit b21db2511a9e32db485d32319fc3e6482a272211)
This commit is contained in:
dab246
2023-05-31 15:38:08 +07:00
committed by Dat Vu
parent 13a698bc92
commit 5fde461d44
@@ -48,7 +48,7 @@ class RichTextWebController extends BaseRichTextController {
} }
void onEditorSettingsChange(EditorSettings settings) async { void onEditorSettingsChange(EditorSettings settings) async {
log('RichTextWebController::onEditorSettingsChange():'); log('RichTextWebController::onEditorSettingsChange():foregroundColor: ${settings.foregroundColor} | backgroundColor: ${settings.backgroundColor}');
listTextStyleApply.clear(); listTextStyleApply.clear();
if (settings.isBold) { if (settings.isBold) {
@@ -68,57 +68,44 @@ class RichTextWebController extends BaseRichTextController {
} }
log('RichTextWebController::onEditorSettingsChange(): $listTextStyleApply'); log('RichTextWebController::onEditorSettingsChange(): $listTextStyleApply');
selectedTextColor.value = settings.foregroundColor;
selectedTextBackgroundColor.value = settings.backgroundColor;
selectedFontName.value = FontNameType.values.firstWhereOrNull((font) => font.name == settings.fontName) ?? FontNameType.sansSerif;
if (settings.isAlignCenter) {
selectedParagraph.value = ParagraphType.alignCenter;
} else if (settings.isAlignJustify) {
selectedParagraph.value = ParagraphType.justify;
} else if (settings.isAlignLeft) {
selectedParagraph.value = ParagraphType.alignLeft;
} 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) { void applyRichTextStyle(BuildContext context, RichTextStyleType textStyleType) {
switch(textStyleType) { switch(textStyleType) {
case RichTextStyleType.textColor: case RichTextStyleType.textColor:
openMenuSelectColor( openMenuSelectColor(
context, context,
selectedTextColor.value, selectedTextColor.value,
onResetToDefault: () { onResetToDefault: () => _applyForegroundColor(Colors.black),
final colorAsString = Colors.black.toHexTriplet(); onSelectColor: _applyForegroundColor
selectedTextColor.value = Colors.black;
editorController.execCommand(
textStyleType.commandAction,
argument: colorAsString);
editorController.setFocus();
},
onSelectColor: (selectedColor) {
final newColor = selectedColor ?? Colors.black;
final colorAsString = newColor.toHexTriplet();
log('RichTextWebController::applyRichTextStyle():selectedTextColor: colorAsString: $colorAsString');
selectedTextColor.value = newColor;
editorController.execCommand(
textStyleType.commandAction,
argument: colorAsString);
editorController.setFocus();
}
); );
break; break;
case RichTextStyleType.textBackgroundColor: case RichTextStyleType.textBackgroundColor:
openMenuSelectColor( openMenuSelectColor(
context, context,
selectedTextBackgroundColor.value, selectedTextBackgroundColor.value,
onResetToDefault: () { onResetToDefault: () => applyBackgroundColor(Colors.white),
final colorAsString = Colors.white.toHexTriplet(); onSelectColor: applyBackgroundColor
log('RichTextWebController::applyRichTextStyle():onResetToDefault: colorAsString: $colorAsString');
selectedTextBackgroundColor.value = Colors.white;
editorController.execCommand(
textStyleType.commandAction,
argument: colorAsString);
editorController.setFocus();
},
onSelectColor: (selectedColor) {
final newColor = selectedColor ?? Colors.white;
final colorAsString = newColor.toHexTriplet();
log('RichTextWebController::applyRichTextStyle():textBackgroundColor: colorAsString: $colorAsString');
selectedTextBackgroundColor.value = newColor;
editorController.execCommand(
textStyleType.commandAction,
argument: colorAsString);
editorController.setFocus();
}
); );
break; break;
default: default:
@@ -129,6 +116,24 @@ class RichTextWebController extends BaseRichTextController {
} }
} }
void _applyForegroundColor(Color? selectedColor) {
final newColor = selectedColor ?? Colors.black;
final colorAsString = newColor.toHexTriplet();
log('RichTextWebController::_applyForegroundColor():colorAsString: $colorAsString');
selectedTextColor.value = newColor;
editorController.execCommand(RichTextStyleType.textColor.commandAction, argument: colorAsString);
editorController.setFocus();
}
void applyBackgroundColor(Color? selectedColor) {
final newColor = selectedColor ?? Colors.white;
final colorAsString = newColor.toHexTriplet();
log('RichTextWebController::_applyBackgroundColor():colorAsString: $colorAsString');
selectedTextBackgroundColor.value = newColor;
editorController.execCommand(RichTextStyleType.textBackgroundColor.commandAction, argument: colorAsString);
editorController.setFocus();
}
void _selectTextStyleType(RichTextStyleType textStyleType) { void _selectTextStyleType(RichTextStyleType textStyleType) {
if (listTextStyleApply.contains(textStyleType)) { if (listTextStyleApply.contains(textStyleType)) {
listTextStyleApply.remove(textStyleType); listTextStyleApply.remove(textStyleType);