feat: add reset font button in toolbar

This commit is contained in:
Lucas.Xu 2023-09-22 15:49:11 +08:00
parent 5dfc470873
commit 57b78ee3c6
4 changed files with 54 additions and 0 deletions

View File

@ -137,6 +137,9 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage> {
convertibleBlockTypes.add(ToggleListBlockKeys.type); convertibleBlockTypes.add(ToggleListBlockKeys.type);
slashMenuItems = _customSlashMenuItems(); slashMenuItems = _customSlashMenuItems();
effectiveScrollController = widget.scrollController ?? ScrollController(); effectiveScrollController = widget.scrollController ?? ScrollController();
// keep the previous font style when typing new text.
AppFlowyRichTextKeys.supportSliced.add(AppFlowyRichTextKeys.fontFamily);
} }
@override @override

View File

@ -20,6 +20,7 @@ final customizeFontToolbarItem = ToolbarItem(
popoverController: popoverController, popoverController: popoverController,
onOpen: () => keepEditorFocusNotifier.value += 1, onOpen: () => keepEditorFocusNotifier.value += 1,
onClose: () => keepEditorFocusNotifier.value -= 1, onClose: () => keepEditorFocusNotifier.value -= 1,
showResetButton: true,
onFontFamilyChanged: (fontFamily) async { onFontFamilyChanged: (fontFamily) async {
await popoverController.close(); await popoverController.close();
try { try {
@ -30,6 +31,9 @@ final customizeFontToolbarItem = ToolbarItem(
Log.error('Failed to set font family: $e'); Log.error('Failed to set font family: $e');
} }
}, },
onResetFont: () async => await editorState.formatDelta(selection, {
AppFlowyRichTextKeys.fontFamily: null,
}),
child: const Padding( child: const Padding(
padding: EdgeInsets.symmetric(horizontal: 4.0), padding: EdgeInsets.symmetric(horizontal: 4.0),
child: FlowySvg( child: FlowySvg(

View File

@ -61,6 +61,8 @@ class FontFamilyDropDown extends StatefulWidget {
this.child, this.child,
this.popoverController, this.popoverController,
this.offset, this.offset,
this.showResetButton = false,
this.onResetFont,
}); });
final String currentFontFamily; final String currentFontFamily;
@ -70,6 +72,8 @@ class FontFamilyDropDown extends StatefulWidget {
final Widget? child; final Widget? child;
final PopoverController? popoverController; final PopoverController? popoverController;
final Offset? offset; final Offset? offset;
final bool showResetButton;
final VoidCallback? onResetFont;
@override @override
State<FontFamilyDropDown> createState() => _FontFamilyDropDownState(); State<FontFamilyDropDown> createState() => _FontFamilyDropDownState();
@ -96,6 +100,13 @@ class _FontFamilyDropDownState extends State<FontFamilyDropDown> {
return CustomScrollView( return CustomScrollView(
shrinkWrap: true, shrinkWrap: true,
slivers: [ slivers: [
if (widget.showResetButton)
SliverPersistentHeader(
delegate: _ResetFontButton(
onPressed: widget.onResetFont,
),
pinned: true,
),
SliverPadding( SliverPadding(
padding: const EdgeInsets.only(right: 8), padding: const EdgeInsets.only(right: 8),
sliver: SliverToBoxAdapter( sliver: SliverToBoxAdapter(
@ -191,3 +202,36 @@ class _FontFamilyDropDownState extends State<FontFamilyDropDown> {
); );
} }
} }
class _ResetFontButton extends SliverPersistentHeaderDelegate {
_ResetFontButton({
this.onPressed,
});
final VoidCallback? onPressed;
@override
Widget build(
BuildContext context,
double shrinkOffset,
bool overlapsContent,
) {
return Padding(
padding: const EdgeInsets.only(right: 8, bottom: 8.0),
child: FlowyTextButton(
LocaleKeys.document_toolbar_resetToDefaultFont.tr(),
onPressed: onPressed,
),
);
}
@override
double get maxExtent => 35;
@override
double get minExtent => 35;
@override
bool shouldRebuild(covariant SliverPersistentHeaderDelegate oldDelegate) =>
true;
}

View File

@ -647,6 +647,9 @@
"label": "Link to page", "label": "Link to page",
"tooltip": "Click to open page" "tooltip": "Click to open page"
} }
},
"toolbar": {
"resetToDefaultFont": "Reset to default"
} }
}, },
"board": { "board": {