feat: use font name instead of name_regular (#5163)

This commit is contained in:
Lucas.Xu 2024-04-29 11:41:25 +08:00 committed by GitHub
parent 3fce5eebf8
commit 3c446d5e78
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 9 deletions

View File

@ -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,
});
}
}

View File

@ -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
}

View File

@ -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<FontFamilyDropDown> {
: null,
onTap: () {
if (widget.onFontFamilyChanged != null) {
widget.onFontFamilyChanged!(style.fontFamily!);
widget.onFontFamilyChanged!(buttonFontFamily);
} else {
final fontFamily = style.fontFamily!.parseFontFamilyName();
if (widget.currentFontFamily.parseFontFamilyName() !=