From 3c446d5e7872115dc0e1a059e209cb7aca4fc56e Mon Sep 17 00:00:00 2001 From: "Lucas.Xu" Date: Mon, 29 Apr 2024 11:41:25 +0800 Subject: [PATCH] feat: use font name instead of name_regular (#5163) --- .../mobile_toolbar_v3/aa_menu/_font_item.dart | 3 +-- .../document/presentation/editor_style.dart | 16 ++++++++++++---- .../settings_appearance/font_family_setting.dart | 5 ++--- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/aa_menu/_font_item.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/aa_menu/_font_item.dart index 0265ea2c02..0558b176b2 100644 --- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/aa_menu/_font_item.dart +++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/aa_menu/_font_item.dart @@ -51,8 +51,7 @@ class FontFamilyItem extends StatelessWidget { if (newFont != null && !selection.isCollapsed) { if (newFont != fontFamily) { await editorState.formatDelta(selection, { - AppFlowyRichTextKeys.fontFamily: - GoogleFonts.getFont(newFont).fontFamily, + AppFlowyRichTextKeys.fontFamily: newFont, }); } } diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_style.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_style.dart index 044a96098c..83dde0036b 100644 --- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_style.dart +++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_style.dart @@ -1,8 +1,5 @@ import 'dart:math'; -import 'package:flutter/gestures.dart'; -import 'package:flutter/material.dart'; - import 'package:appflowy/core/helpers/url_launcher.dart'; import 'package:appflowy/plugins/document/application/document_appearance_cubit.dart'; import 'package:appflowy/plugins/document/presentation/editor_plugins/mention/mention_block.dart'; @@ -15,6 +12,8 @@ import 'package:appflowy/workspace/application/settings/appearance/appearance_cu import 'package:appflowy/workspace/application/settings/appearance/base_appearance.dart'; import 'package:appflowy_editor/appflowy_editor.dart' hide Log; import 'package:collection/collection.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:go_router/go_router.dart'; import 'package:google_fonts/google_fonts.dart'; @@ -248,7 +247,16 @@ class EditorStyleCustomizer { // try to refresh font here. if (attributes.fontFamily != null) { try { - GoogleFonts.getFont(attributes.fontFamily!.parseFontFamilyName()); + if (before.text?.contains('_regular') == true) { + GoogleFonts.getFont(attributes.fontFamily!.parseFontFamilyName()); + } else { + return TextSpan( + text: before.text, + style: after.style?.merge( + GoogleFonts.getFont(attributes.fontFamily!), + ), + ); + } } catch (e) { // ignore } diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/settings_appearance/font_family_setting.dart b/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/settings_appearance/font_family_setting.dart index 7a25e2f032..d06b160fcf 100644 --- a/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/settings_appearance/font_family_setting.dart +++ b/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/settings_appearance/font_family_setting.dart @@ -1,5 +1,3 @@ -import 'package:flutter/material.dart'; - import 'package:appflowy/generated/flowy_svgs.g.dart'; import 'package:appflowy/generated/locale_keys.g.dart'; import 'package:appflowy/plugins/document/application/document_appearance_cubit.dart'; @@ -10,6 +8,7 @@ import 'package:appflowy_popover/appflowy_popover.dart'; import 'package:collection/collection.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:flowy_infra_ui/flowy_infra_ui.dart'; +import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:google_fonts/google_fonts.dart'; @@ -186,7 +185,7 @@ class _FontFamilyDropDownState extends State { : null, onTap: () { if (widget.onFontFamilyChanged != null) { - widget.onFontFamilyChanged!(style.fontFamily!); + widget.onFontFamilyChanged!(buttonFontFamily); } else { final fontFamily = style.fontFamily!.parseFontFamilyName(); if (widget.currentFontFamily.parseFontFamilyName() !=