fix: the cursor will jump up when creating a new document on desktop. (#5269)

* fix: the cursor will jump up when creating a new document on desktop

* fix: the titlbar flashes when switching to another page

* fix: unit test

* fix: default font family copy
This commit is contained in:
Lucas.Xu 2024-05-06 15:50:32 +08:00 committed by GitHub
parent b2c366f6ae
commit 9f44ae959a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 38 additions and 23 deletions

View File

@ -73,7 +73,7 @@ void main() {
await tester.openSettingsPage(SettingsPage.files);
await tester.openSettingsPage(SettingsPage.appearance);
final resetButton = find.byKey(ThemeFontFamilySetting.resetButtonkey);
final resetButton = find.byKey(ThemeFontFamilySetting.resetButtonKey);
await tester.tap(resetButton);
await tester.pumpAndSettle();

View File

@ -170,7 +170,7 @@ SPEC CHECKSUMS:
file_picker: 09aa5ec1ab24135ccd7a1621c46c84134bfd6655
flowy_infra_ui: 0455e1fa8c51885aa1437848e361e99419f34ebc
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
fluttertoast: fafc4fa4d01a6a9e4f772ecd190ffa525e9e2d9c
fluttertoast: 31b00dabfa7fb7bacd9e7dbee580d7a2ff4bf265
image_gallery_saver: cb43cc43141711190510e92c460eb1655cd343cb
image_picker_ios: 99dfe1854b4fa34d0364e74a78448a0151025425
integration_test: 13825b8a9334a850581300559b8839134b124670
@ -191,4 +191,4 @@ SPEC CHECKSUMS:
PODFILE CHECKSUM: d0d9b4ff572d8695c38eb3f9b490f55cdfc57eca
COCOAPODS: 1.11.3
COCOAPODS: 1.15.2

View File

@ -106,12 +106,14 @@ class _FontSelectorState extends State<FontSelector> {
}
final fontFamilyName = availableFonts[index - 1];
final fontFamily = fontFamilyName != builtInFontFamily()
final usingDefaultFontFamily = fontFamilyName == builtInFontFamily();
final fontFamily = !usingDefaultFontFamily
? getGoogleFontSafely(fontFamilyName).fontFamily
: TextStyle(fontFamily: builtInFontFamily()).fontFamily;
return FlowyOptionTile.checkbox(
// display the default font name if the font family name is empty
text: fontFamilyName.isNotEmpty
// or using the default font family
text: fontFamilyName.isNotEmpty && !usingDefaultFontFamily
? fontFamilyName.parseFontFamilyName()
: LocaleKeys.settings_appearance_fontFamily_defaultFont.tr(),
isSelected: widget.selectedFontFamilyName == fontFamilyName,

View File

@ -4,6 +4,7 @@ import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/presentation/setting/font/font_picker_screen.dart';
import 'package:appflowy/plugins/document/application/document_appearance_cubit.dart';
import 'package:appflowy/workspace/application/settings/appearance/appearance_cubit.dart';
import 'package:appflowy/workspace/application/settings/appearance/base_appearance.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flutter/material.dart';
@ -21,13 +22,16 @@ class FontSetting extends StatelessWidget {
Widget build(BuildContext context) {
final theme = Theme.of(context);
final selectedFont = context.watch<AppearanceSettingsCubit>().state.font;
final name = selectedFont == builtInFontFamily()
? LocaleKeys.settings_appearance_fontFamily_defaultFont.tr()
: selectedFont;
return MobileSettingItem(
name: LocaleKeys.settings_appearance_fontFamily_label.tr(),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
FlowyText(
selectedFont,
name,
color: theme.colorScheme.onSurface,
),
const Icon(Icons.chevron_right),

View File

@ -89,7 +89,7 @@ class _DocumentCoverWidgetState extends State<DocumentCoverWidget> {
bool get hasIcon => viewIcon.isNotEmpty;
bool get hasCover =>
coverType != CoverType.none ||
cover?.type != PageStyleCoverImageType.none;
(cover != null && cover?.type != PageStyleCoverImageType.none);
String viewIcon = '';
PageStyleCover? cover;

View File

@ -18,7 +18,7 @@ enum OpenAIRequestType {
case OpenAIRequestType.textCompletion:
return Uri.parse('https://api.openai.com/v1/completions');
case OpenAIRequestType.textEdit:
return Uri.parse('https://api.openai.com/v1/v1/chat/completions');
return Uri.parse('https://api.openai.com/v1/chat/completions');
case OpenAIRequestType.imageGenerations:
return Uri.parse('https://api.openai.com/v1/images/generations');
}

View File

@ -163,6 +163,11 @@ class _FontButton extends StatelessWidget {
Widget build(BuildContext context) {
return BlocBuilder<DocumentPageStyleBloc, DocumentPageStyleState>(
builder: (context, state) {
String fontFamily = state.fontFamily ?? builtInFontFamily();
if (fontFamily == builtInFontFamily()) {
fontFamily =
LocaleKeys.settings_appearance_fontFamily_defaultFont.tr();
}
return GestureDetector(
onTap: () => _showFontSelector(context),
behavior: HitTestBehavior.opaque,
@ -177,7 +182,7 @@ class _FontButton extends StatelessWidget {
const HSpace(16.0),
FlowyText(LocaleKeys.titleBar_font.tr()),
const Spacer(),
FlowyText(state.fontFamily ?? builtInFontFamily()),
FlowyText(fontFamily),
const HSpace(6.0),
const FlowySvg(FlowySvgs.m_page_style_arrow_right_s),
const HSpace(12.0),

View File

@ -24,7 +24,7 @@ class ThemeFontFamilySetting extends StatefulWidget {
final String currentFontFamily;
static Key textFieldKey = const Key('FontFamilyTextField');
static Key resetButtonkey = const Key('FontFamilyResetButton');
static Key resetButtonKey = const Key('FontFamilyResetButton');
static Key popoverKey = const Key('FontFamilyPopover');
@override
@ -36,7 +36,7 @@ class _ThemeFontFamilySettingState extends State<ThemeFontFamilySetting> {
Widget build(BuildContext context) {
return FlowySettingListTile(
label: LocaleKeys.settings_appearance_fontFamily_label.tr(),
resetButtonKey: ThemeFontFamilySetting.resetButtonkey,
resetButtonKey: ThemeFontFamilySetting.resetButtonKey,
onResetRequested: () {
context.read<AppearanceSettingsCubit>().resetFontFamily();
context

View File

@ -31,12 +31,14 @@ class ViewTitleBar extends StatefulWidget {
class _ViewTitleBarState extends State<ViewTitleBar> {
late Future<List<ViewPB>> ancestors;
late String viewId;
@override
void initState() {
super.initState();
_reloadAncestors();
viewId = widget.view.id;
_reloadAncestors(viewId);
}
@override
@ -44,7 +46,8 @@ class _ViewTitleBarState extends State<ViewTitleBar> {
super.didUpdateWidget(oldWidget);
if (oldWidget.view.id != widget.view.id) {
_reloadAncestors();
viewId = widget.view.id;
_reloadAncestors(viewId);
}
}
@ -54,10 +57,11 @@ class _ViewTitleBarState extends State<ViewTitleBar> {
future: ancestors,
builder: (context, snapshot) {
final ancestors = snapshot.data;
if (ancestors == null) {
if (ancestors == null ||
snapshot.connectionState != ConnectionState.done) {
return const SizedBox.shrink();
}
const maxWidth = WindowSizeManager.minWindowWidth - 200;
const maxWidth = WindowSizeManager.minWindowWidth / 2.0;
final replacement = Row(
// refresh the view title bar when the ancestors changed
key: ValueKey(ancestors.hashCode),
@ -73,7 +77,7 @@ class _ViewTitleBarState extends State<ViewTitleBar> {
key: ValueKey(ancestors.last),
view: ancestors.last,
maxTitleWidth: constraints.maxWidth,
onUpdated: () => setState(() => _reloadAncestors()),
onUpdated: () => setState(() => _reloadAncestors(viewId)),
),
);
},
@ -129,7 +133,7 @@ class _ViewTitleBarState extends State<ViewTitleBar> {
behavior: i == views.length - 1
? _ViewTitleBehavior.editable // only the last one is editable
: _ViewTitleBehavior.uneditable, // others are not editable
onUpdated: () => setState(() => _reloadAncestors()),
onUpdated: () => setState(() => _reloadAncestors(viewId)),
),
);
}
@ -144,8 +148,8 @@ class _ViewTitleBarState extends State<ViewTitleBar> {
return children;
}
void _reloadAncestors() {
ancestors = ViewBackendService.getViewAncestors(widget.view.id)
void _reloadAncestors(String viewId) {
ancestors = ViewBackendService.getViewAncestors(viewId)
.fold((s) => s.items, (f) => []);
}
}

View File

@ -25,7 +25,7 @@ class TrashTestContext {
section: ViewSectionPB.Public,
),
);
await blocResponseFuture();
await blocResponseFuture(millisecond: 300);
viewBloc.add(
const ViewEvent.createView(
@ -34,7 +34,7 @@ class TrashTestContext {
section: ViewSectionPB.Public,
),
);
await blocResponseFuture();
await blocResponseFuture(millisecond: 300);
viewBloc.add(
const ViewEvent.createView(
@ -43,7 +43,7 @@ class TrashTestContext {
section: ViewSectionPB.Public,
),
);
await blocResponseFuture();
await blocResponseFuture(millisecond: 300);
allViews = [...viewBloc.state.view.childViews];
assert(allViews.length == 3, 'but receive ${allViews.length}');

View File

@ -412,7 +412,7 @@
"fontFamily": {
"label": "Font Family",
"search": "Search",
"defaultFont": "Default Font"
"defaultFont": "System"
},
"themeMode": {
"label": "Theme Mode",