TF-1877 Use execSummernoteAPI to format text style

(cherry picked from commit 6c81bef9a0cbe391ebf42096dc33ae0d99cf79c8)
This commit is contained in:
dab246
2023-06-30 12:57:10 +07:00
committed by Dat Vu
parent 7f4b0c4b52
commit 32adfb3581
9 changed files with 253 additions and 23 deletions
@@ -134,9 +134,8 @@ class RichTextWebController extends BaseRichTextController {
);
break;
default:
editorController.execCommand(textStyleType.commandAction);
editorController.execSummernoteAPI(textStyleType.summernoteNameAPI);
_selectTextStyleType(textStyleType);
editorController.setFocus();
break;
}
}
@@ -146,8 +145,9 @@ class RichTextWebController extends BaseRichTextController {
final colorAsString = newColor.toHexTriplet();
log('RichTextWebController::_applyForegroundColor():colorAsString: $colorAsString');
selectedTextColor.value = newColor;
editorController.execCommand(RichTextStyleType.textColor.commandAction, argument: colorAsString);
editorController.setFocus();
editorController.execSummernoteAPI(
RichTextStyleType.textColor.summernoteNameAPI,
value: colorAsString);
}
void applyBackgroundColor(Color? selectedColor) {
@@ -155,8 +155,9 @@ class RichTextWebController extends BaseRichTextController {
final colorAsString = newColor.toHexTriplet();
log('RichTextWebController::_applyBackgroundColor():colorAsString: $colorAsString');
selectedTextBackgroundColor.value = newColor;
editorController.execCommand(RichTextStyleType.textBackgroundColor.commandAction, argument: colorAsString);
editorController.setFocus();
editorController.execSummernoteAPI(
RichTextStyleType.textBackgroundColor.summernoteNameAPI,
value: colorAsString);
}
void _selectTextStyleType(RichTextStyleType textStyleType) {
@@ -182,10 +183,9 @@ class RichTextWebController extends BaseRichTextController {
void applyNewFontStyle(FontNameType? newFont) {
final fontSelected = newFont ?? FontNameType.sansSerif;
selectedFontName.value = fontSelected;
editorController.execCommand(
RichTextStyleType.fontName.commandAction,
argument: fontSelected.value);
editorController.setFocus();
editorController.execSummernoteAPI(
RichTextStyleType.fontName.summernoteNameAPI,
value: fontSelected.value);
}
bool get isMenuFontOpen => menuFontStatus.value == DropdownMenuFontStatus.open;
@@ -220,17 +220,20 @@ class RichTextWebController extends BaseRichTextController {
void applyHeaderStyle(HeaderStyleType? newStyle) {
final styleSelected = newStyle ?? HeaderStyleType.normal;
editorController.execCommand(
if (styleSelected == HeaderStyleType.blockquote || styleSelected == HeaderStyleType.code) {
editorController.execCommand(
RichTextStyleType.headerStyle.commandAction,
argument: styleSelected.styleValue);
editorController.setFocus();
editorController.setFocus();
} else {
editorController.execSummernoteAPI(styleSelected.summernoteNameAPI);
}
}
void applyParagraphType(ParagraphType newParagraph) {
selectedParagraph.value = newParagraph;
editorController.execCommand(newParagraph.commandAction);
editorController.execSummernoteAPI(newParagraph.summernoteNameAPI);
menuParagraphController.hideMenu();
editorController.setFocus();
}
void closeAllMenuPopup() {
@@ -250,9 +253,8 @@ class RichTextWebController extends BaseRichTextController {
void applyOrderListType(OrderListType newOrderList) {
selectedOrderList.value = newOrderList;
editorController.execCommand(newOrderList.commandAction);
editorController.execSummernoteAPI(newOrderList.summernoteNameAPI);
menuOrderListController.hideMenu();
editorController.setFocus();
}
@override
@@ -58,6 +58,27 @@ enum HeaderStyleType {
}
}
String get summernoteNameAPI {
switch (this) {
case HeaderStyleType.normal:
return 'formatPara';
case HeaderStyleType.h1:
return 'formatH1';
case HeaderStyleType.h2:
return 'formatH2';
case HeaderStyleType.h3:
return 'formatH3';
case HeaderStyleType.h4:
return 'formatH4';
case HeaderStyleType.h5:
return 'formatH5';
case HeaderStyleType.h6:
return 'formatH6';
default:
return '';
}
}
double get textSize {
switch(this) {
case HeaderStyleType.normal:
@@ -17,6 +17,15 @@ enum OrderListType {
}
}
String get summernoteNameAPI {
switch(this) {
case OrderListType.bulletedList:
return 'insertUnorderedList';
case OrderListType.numberedList:
return 'insertOrderedList';
}
}
String getIcon(ImagePaths imagePaths) {
switch (this) {
case OrderListType.bulletedList:
@@ -29,6 +29,23 @@ enum ParagraphType {
}
}
String get summernoteNameAPI {
switch(this) {
case ParagraphType.alignLeft:
return 'justifyLeft';
case ParagraphType.alignRight:
return 'justifyRight';
case ParagraphType.alignCenter:
return 'justifyCenter';
case ParagraphType.justify:
return 'justifyFull';
case ParagraphType.indent:
return 'indent';
case ParagraphType.outdent:
return 'outdent';
}
}
String getIcon(ImagePaths imagePaths) {
switch (this) {
case ParagraphType.alignLeft:
@@ -38,6 +38,27 @@ enum RichTextStyleType {
}
}
String get summernoteNameAPI {
switch (this) {
case RichTextStyleType.textColor:
return 'foreColor';
case RichTextStyleType.textBackgroundColor:
return 'backColor';
case RichTextStyleType.fontName:
return 'fontName';
case bold:
return 'bold';
case italic:
return 'italic';
case underline:
return 'underline';
case strikeThrough:
return 'strikethrough';
default:
return '';
}
}
String getIcon(ImagePaths imagePaths) {
switch (this) {
case bold:
@@ -114,9 +114,9 @@ class ComposerStyle {
static EdgeInsetsGeometry getEditorPadding(BuildContext context, ResponsiveUtils responsiveUtils) {
if (PlatformInfo.isWeb) {
if (responsiveUtils.isMobile(context)) {
return const EdgeInsetsDirectional.symmetric(horizontal: 16);
return const EdgeInsetsDirectional.symmetric(horizontal: 6);
} else {
return const EdgeInsetsDirectional.only(start: 88, end: 48);
return const EdgeInsetsDirectional.only(start: 78, end: 38);
}
} else {
if (responsiveUtils.isPortraitMobile(context) || responsiveUtils.isLandscapeMobile(context)) {