Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

feat: support cover title (#6353)

Lucas4c6b6ffdaca8
diff --git a/frontend/appflowy_flutter/integration_test/desktop/database/database_row_cover_test.dart b/frontend/appflowy_flutter/integration_test/desktop/database/database_row_cover_test.dart
index 4aee8e1feb..979cd0f98f 100644
--- a/frontend/appflowy_flutter/integration_test/desktop/database/database_row_cover_test.dart
+++ b/frontend/appflowy_flutter/integration_test/desktop/database/database_row_cover_test.dart
@@ -1,19 +1,18 @@
import 'dart:io';
-import 'package:flutter/services.dart';
-
import 'package:appflowy/core/config/kv.dart';
import 'package:appflowy/core/config/kv_keys.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/database/widgets/card/card.dart';
import 'package:appflowy/plugins/database/widgets/cell_editor/media_cell_editor.dart';
import 'package:appflowy/plugins/database/widgets/row/row_banner.dart';
-import 'package:appflowy/plugins/document/presentation/editor_plugins/header/document_header_node_widget.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';
import 'package:appflowy/shared/af_image.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/field_entities.pbenum.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pbenum.dart';
import 'package:easy_localization/easy_localization.dart';
+import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:path/path.dart' as p;
diff --git a/frontend/appflowy_flutter/integration_test/desktop/document/document_codeblock_paste_test.dart b/frontend/appflowy_flutter/integration_test/desktop/document/document_codeblock_paste_test.dart
index 0fb8cc90e8..a498086952 100644
--- a/frontend/appflowy_flutter/integration_test/desktop/document/document_codeblock_paste_test.dart
+++ b/frontend/appflowy_flutter/integration_test/desktop/document/document_codeblock_paste_test.dart
@@ -13,13 +13,15 @@ import '../../shared/util.dart';
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
- group('paste in codeblock', () {
+ group('paste in codeblock:', () {
testWidgets('paste multiple lines in codeblock', (tester) async {
await tester.initializeAppFlowy();
await tester.tapAnonymousSignInButton();
// create a new document
- await tester.createNewPageWithNameUnderParent();
+ await tester.createNewPageWithNameUnderParent(name: 'Test Document');
+ // focus on the editor
+ await tester.tapButton(find.byType(AppFlowyEditor));
// mock the clipboard
const lines = 3;
diff --git a/frontend/appflowy_flutter/integration_test/desktop/document/document_copy_and_paste_test.dart b/frontend/appflowy_flutter/integration_test/desktop/document/document_copy_and_paste_test.dart
index d178f584b0..1fa38c09ea 100644
--- a/frontend/appflowy_flutter/integration_test/desktop/document/document_copy_and_paste_test.dart
+++ b/frontend/appflowy_flutter/integration_test/desktop/document/document_copy_and_paste_test.dart
@@ -336,7 +336,9 @@ extension on WidgetTester {
await tapAnonymousSignInButton();
// create a new document
- await createNewPageWithNameUnderParent();
+ await createNewPageWithNameUnderParent(name: 'Test Document');
+ // tap the editor
+ await tapButton(find.byType(AppFlowyEditor));
await beforeTest?.call(editor.getCurrentEditorState());
diff --git a/frontend/appflowy_flutter/integration_test/desktop/document/document_create_and_delete_test.dart b/frontend/appflowy_flutter/integration_test/desktop/document/document_create_and_delete_test.dart
index cf45afc828..43320509ce 100644
--- a/frontend/appflowy_flutter/integration_test/desktop/document/document_create_and_delete_test.dart
+++ b/frontend/appflowy_flutter/integration_test/desktop/document/document_create_and_delete_test.dart
@@ -1,6 +1,4 @@
-import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
-import 'package:easy_localization/easy_localization.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
@@ -17,12 +15,11 @@ void main() {
await tester.tapAnonymousSignInButton();
// create a new document
- await tester.createNewPageWithNameUnderParent();
+ const pageName = 'Test Document';
+ await tester.createNewPageWithNameUnderParent(name: pageName);
// expect to see a new document
- tester.expectToSeePageName(
- LocaleKeys.menuAppHeader_defaultNewPageName.tr(),
- );
+ tester.expectToSeePageName(pageName);
// and with one paragraph block
expect(find.byType(ParagraphBlockComponentWidget), findsOneWidget);
});
diff --git a/frontend/appflowy_flutter/integration_test/desktop/document/document_title_test.dart b/frontend/appflowy_flutter/integration_test/desktop/document/document_title_test.dart
new file mode 100644
index 0000000000..3299a5f755
--- /dev/null
+++ b/frontend/appflowy_flutter/integration_test/desktop/document/document_title_test.dart
@@ -0,0 +1,224 @@
+import 'package:appflowy_editor/appflowy_editor.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:integration_test/integration_test.dart';
+import 'package:universal_platform/universal_platform.dart';
+
+import '../../shared/constants.dart';
+import '../../shared/util.dart';
+
+const _testDocumentName = 'Test Document';
+
+void main() {
+ IntegrationTestWidgetsFlutterBinding.ensureInitialized();
+
+ group('document title:', () {
+ testWidgets('create a new document and edit title', (tester) async {
+ await tester.initializeAppFlowy();
+ await tester.tapAnonymousSignInButton();
+
+ // create a new document
+ await tester.createNewPageWithNameUnderParent();
+
+ final title = tester.editor.findDocumentTitle('');
+ expect(title, findsOneWidget);
+
+ // input name
+ await tester.enterText(title, _testDocumentName);
+ await tester.pumpAndSettle();
+
+ final newTitle = tester.editor.findDocumentTitle(_testDocumentName);
+ expect(newTitle, findsOneWidget);
+
+ // press enter to create a new line
+ await tester.simulateKeyEvent(LogicalKeyboardKey.enter);
+ await tester.pumpAndSettle();
+
+ const firstLine = 'First line of text';
+ await tester.ime.insertText(firstLine);
+ await tester.pumpAndSettle();
+
+ final firstLineText = find.text(firstLine, findRichText: true);
+ expect(firstLineText, findsOneWidget);
+
+ // press cmd/ctrl+left to move the cursor to the start of the line
+ if (UniversalPlatform.isMacOS) {
+ await tester.simulateKeyEvent(
+ LogicalKeyboardKey.arrowLeft,
+ isMetaPressed: true,
+ );
+ } else {
+ await tester.simulateKeyEvent(LogicalKeyboardKey.home);
+ }
+ await tester.pumpAndSettle();
+
+ // press arrow left to delete the first line
+ await tester.simulateKeyEvent(LogicalKeyboardKey.arrowLeft);
+ await tester.pumpAndSettle();
+
+ // check if the title is on focus
+ final titleOnFocus = tester.editor.findDocumentTitle(_testDocumentName);
+ final titleWidget = tester.widget<TextField>(titleOnFocus);
+ expect(titleWidget.focusNode?.hasFocus, isTrue);
+
+ // press the right arrow key to move the cursor to the first line
+ await tester.simulateKeyEvent(LogicalKeyboardKey.arrowRight);
+
+ // check if the title is not on focus
+ expect(titleWidget.focusNode?.hasFocus, isFalse);
+
+ final editorState = tester.editor.getCurrentEditorState();
+ expect(editorState.selection, Selection.collapsed(Position(path: [0])));
+
+ // press the backspace key to go to the title
+ await tester.simulateKeyEvent(LogicalKeyboardKey.backspace);
+
+ expect(editorState.selection, null);
+ expect(titleWidget.focusNode?.hasFocus, isTrue);
+ });
+
+ testWidgets('check if the title is saved', (tester) async {
+ await tester.initializeAppFlowy();
+ await tester.tapAnonymousSignInButton();
+
+ // create a new document
+ await tester.createNewPageWithNameUnderParent();
+
+ final title = tester.editor.findDocumentTitle('');
+ expect(title, findsOneWidget);
+
+ // input name
+ await tester.enterText(title, _testDocumentName);
+ await tester.pumpAndSettle();
+
+ if (UniversalPlatform.isLinux) {
+ // wait for the name to be saved
+ await tester.wait(250);
+ }
+
+ // go to the get started page
+ await tester.tapButton(
+ tester.findPageName(Constants.gettingStartedPageName),
+ );
+
+ // go back to the page
+ await tester.tapButton(tester.findPageName(_testDocumentName));
+
+ // check if the title is saved
+ final testDocumentTitle = tester.editor.findDocumentTitle(
+ _testDocumentName,
+ );
+ expect(testDocumentTitle, findsOneWidget);
+ });
+
+ testWidgets('arrow up from first line moves focus to title',
+ (tester) async {
+ await tester.initializeAppFlowy();
+ await tester.tapAnonymousSignInButton();
+
+ await tester.createNewPageWithNameUnderParent();
+
+ final title = tester.editor.findDocumentTitle('');
+ await tester.enterText(title, _testDocumentName);
+ await tester.pumpAndSettle();
+
+ await tester.simulateKeyEvent(LogicalKeyboardKey.enter);
+ await tester.ime.insertText('First line of text');
+ await tester.pumpAndSettle();
+
+ await tester.simulateKeyEvent(LogicalKeyboardKey.home);
+
+ // press the arrow upload
+ await tester.simulateKeyEvent(LogicalKeyboardKey.arrowUp);
+
+ final titleWidget = tester.widget<TextField>(
+ tester.editor.findDocumentTitle(_testDocumentName),
+ );
+ expect(titleWidget.focusNode?.hasFocus, isTrue);
+
+ final editorState = tester.editor.getCurrentEditorState();
+ expect(editorState.selection, null);
+ });
+
+ testWidgets(
+ 'backspace at start of first line moves focus to title and deletes empty paragraph',
+ (tester) async {
+ await tester.initializeAppFlowy();
+ await tester.tapAnonymousSignInButton();
+
+ await tester.createNewPageWithNameUnderParent();
+
+ final title = tester.editor.findDocumentTitle('');
+ await tester.enterText(title, _testDocumentName);
+ await tester.pumpAndSettle();
+
+ await tester.simulateKeyEvent(LogicalKeyboardKey.enter);
+
+ final editorState = tester.editor.getCurrentEditorState();
+ expect(editorState.document.root.children.length, equals(2));
+
+ await tester.simulateKeyEvent(LogicalKeyboardKey.backspace);
+
+ final titleWidget = tester.widget<TextField>(
+ tester.editor.findDocumentTitle(_testDocumentName),
+ );
+ expect(titleWidget.focusNode?.hasFocus, isTrue);
+
+ // at least one empty paragraph node is created
+ expect(editorState.document.root.children.length, equals(1));
+ });
+
+ testWidgets('arrow right from end of title moves focus to first line',
+ (tester) async {
+ await tester.initializeAppFlowy();
+ await tester.tapAnonymousSignInButton();
+
+ await tester.createNewPageWithNameUnderParent();
+
+ final title = tester.editor.findDocumentTitle('');
+ await tester.enterText(title, _testDocumentName);
+ await tester.pumpAndSettle();
+
+ await tester.simulateKeyEvent(LogicalKeyboardKey.enter);
+ await tester.ime.insertText('First line of text');
+
+ await tester.tapButton(
+ tester.editor.findDocumentTitle(_testDocumentName),
+ );
+ await tester.simulateKeyEvent(LogicalKeyboardKey.end);
+ await tester.simulateKeyEvent(LogicalKeyboardKey.arrowRight);
+
+ final editorState = tester.editor.getCurrentEditorState();
+ expect(
+ editorState.selection,
+ Selection.collapsed(
+ Position(path: [0]),
+ ),
+ );
+ });
+
+ testWidgets('change the title via sidebar, check the title is updated',
+ (tester) async {
+ await tester.initializeAppFlowy();
+ await tester.tapAnonymousSignInButton();
+
+ await tester.createNewPageWithNameUnderParent();
+
+ final title = tester.editor.findDocumentTitle('');
+ expect(title, findsOneWidget);
+
+ await tester.hoverOnPageName(
+ '',
+ onHover: () async {
+ await tester.renamePage(_testDocumentName);
+ await tester.pumpAndSettle();
+ },
+ );
+ await tester.pumpAndSettle();
+
+ final newTitle = tester.editor.findDocumentTitle(_testDocumentName);
+ expect(newTitle, findsOneWidget);
+ });
+ });
+}
diff --git a/frontend/appflowy_flutter/integration_test/desktop/document/document_with_cover_image_test.dart b/frontend/appflowy_flutter/integration_test/desktop/document/document_with_cover_image_test.dart
index fd6e0dfa19..641be67769 100644
--- a/frontend/appflowy_flutter/integration_test/desktop/document/document_with_cover_image_test.dart
+++ b/frontend/appflowy_flutter/integration_test/desktop/document/document_with_cover_image_test.dart
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
-import 'package:appflowy/plugins/document/presentation/editor_plugins/header/document_header_node_widget.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/header/document_cover_widget.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter_emoji_mart/flutter_emoji_mart.dart';
diff --git a/frontend/appflowy_flutter/integration_test/desktop/document/document_with_image_block_test.dart b/frontend/appflowy_flutter/integration_test/desktop/document/document_with_image_block_test.dart
index fb0c686824..63d3e32096 100644
--- a/frontend/appflowy_flutter/integration_test/desktop/document/document_with_image_block_test.dart
+++ b/frontend/appflowy_flutter/integration_test/desktop/document/document_with_image_block_test.dart
@@ -161,9 +161,8 @@ void main() {
);
expect(find.byType(UploadImageMenu), findsOneWidget);
- await tester.tapButtonWithName(
- 'Unsplash',
- );
+ await tester.tapButtonWithName('Unsplash');
+ await tester.pumpUntilFound(find.byType(UnsplashImageWidget));
expect(find.byType(UnsplashImageWidget), findsOneWidget);
});
});
diff --git a/frontend/appflowy_flutter/integration_test/desktop/settings/shortcuts_settings_test.dart b/frontend/appflowy_flutter/integration_test/desktop/settings/shortcuts_settings_test.dart
index fb3383a218..5e1227fb6c 100644
--- a/frontend/appflowy_flutter/integration_test/desktop/settings/shortcuts_settings_test.dart
+++ b/frontend/appflowy_flutter/integration_test/desktop/settings/shortcuts_settings_test.dart
@@ -1,11 +1,10 @@
-import 'package:flutter/material.dart';
-import 'package:flutter/services.dart';
-
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/workspace/application/settings/settings_dialog_bloc.dart';
import 'package:appflowy/workspace/presentation/settings/pages/settings_shortcuts_view.dart';
import 'package:easy_localization/easy_localization.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
@@ -16,8 +15,8 @@ import '../board/board_hide_groups_test.dart';
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
- group('shortcuts test', () {
- testWidgets('can change and overwrite shortcut', (tester) async {
+ group('shortcuts:', () {
+ testWidgets('change and overwrite shortcut', (tester) async {
await tester.initializeAppFlowy();
await tester.tapAnonymousSignInButton();
@@ -29,7 +28,11 @@ void main() {
LocaleKeys.settings_shortcutsPage_keybindings_backspace.tr();
// Input "Delete" into the search field
- await tester.enterText(find.byType(TextField), backspaceCmd);
+ final inputField = find.descendant(
+ of: find.byType(SettingsShortcutsView),
+ matching: find.byType(TextField),
+ );
+ await tester.enterText(inputField, backspaceCmd);
await tester.pumpAndSettle();
await tester.hoverOnWidget(
diff --git a/frontend/appflowy_flutter/integration_test/desktop/sidebar/sidebar_test.dart b/frontend/appflowy_flutter/integration_test/desktop/sidebar/sidebar_test.dart
index 006d7ff0b6..e6580dca5f 100644
--- a/frontend/appflowy_flutter/integration_test/desktop/sidebar/sidebar_test.dart
+++ b/frontend/appflowy_flutter/integration_test/desktop/sidebar/sidebar_test.dart
@@ -1,4 +1,3 @@
-import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/database/board/presentation/board_page.dart';
import 'package:appflowy/plugins/database/calendar/presentation/calendar_page.dart';
import 'package:appflowy/plugins/database/grid/presentation/grid_page.dart';
@@ -8,7 +7,6 @@ import 'package:appflowy/workspace/presentation/home/menu/view/view_item.dart';
import 'package:appflowy/workspace/presentation/home/menu/view/view_more_action_button.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
-import 'package:easy_localization/easy_localization.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
@@ -17,7 +15,7 @@ import '../../shared/util.dart';
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
- group('sidebar test', () {
+ group('sidebar:', () {
testWidgets('create a new page', (tester) async {
await tester.initializeAppFlowy();
await tester.tapAnonymousSignInButton();
@@ -26,9 +24,7 @@ void main() {
await tester.tapNewPageButton();
// expect to see a new document
- tester.expectToSeePageName(
- LocaleKeys.menuAppHeader_defaultNewPageName.tr(),
- );
+ tester.expectToSeePageName('');
// and with one paragraph block
expect(find.byType(ParagraphBlockComponentWidget), findsOneWidget);
});
diff --git a/frontend/appflowy_flutter/integration_test/desktop/uncategorized/zoom_in_out_test.dart b/frontend/appflowy_flutter/integration_test/desktop/uncategorized/zoom_in_out_test.dart
index e7e95edbe4..f0cddadf68 100644
--- a/frontend/appflowy_flutter/integration_test/desktop/uncategorized/zoom_in_out_test.dart
+++ b/frontend/appflowy_flutter/integration_test/desktop/uncategorized/zoom_in_out_test.dart
@@ -12,7 +12,7 @@ import '../../shared/common_operations.dart';
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
- group('Zoom in/out: ', () {
+ group('Zoom in/out:', () {
Future<void> resetAppFlowyScaleFactor(
WindowSizeManager windowSizeManager,
) async {
diff --git a/frontend/appflowy_flutter/integration_test/desktop_runner_3.dart b/frontend/appflowy_flutter/integration_test/desktop_runner_3.dart
index 3ddfb0c4d0..8e2b120b21 100644
--- a/frontend/appflowy_flutter/integration_test/desktop_runner_3.dart
+++ b/frontend/appflowy_flutter/integration_test/desktop_runner_3.dart
@@ -3,6 +3,7 @@ import 'package:integration_test/integration_test.dart';
import 'desktop/board/board_test_runner.dart' as board_test_runner;
import 'desktop/database/database_row_cover_test.dart'
as database_row_cover_test;
+import 'desktop/document/document_title_test.dart' as document_title_test;
import 'desktop/grid/grid_create_row_test.dart' as grid_create_row_test_runner;
import 'desktop/grid/grid_filter_and_sort_test.dart'
as grid_filter_and_sort_test_runner;
@@ -44,6 +45,6 @@ Future<void> runIntegration3OnDesktop() async {
grid_create_row_test_runner.main();
grid_reorder_row_test_runner.main();
grid_filter_and_sort_test_runner.main();
-
zoom_in_out_test.main();
+ document_title_test.main();
}
diff --git a/frontend/appflowy_flutter/integration_test/shared/common_operations.dart b/frontend/appflowy_flutter/integration_test/shared/common_operations.dart
index 8c33468d3b..96816a26b2 100644
--- a/frontend/appflowy_flutter/integration_test/shared/common_operations.dart
+++ b/frontend/appflowy_flutter/integration_test/shared/common_operations.dart
@@ -314,10 +314,14 @@ extension CommonOperations on WidgetTester {
}
await pumpAndSettle();
+ final defaultPageName = layout == ViewLayoutPB.Document
+ ? '' // the document name is empty by default
+ : LocaleKeys.menuAppHeader_defaultNewPageName.tr();
+
// hover on it and change it's name
if (name != null) {
await hoverOnPageName(
- LocaleKeys.menuAppHeader_defaultNewPageName.tr(),
+ defaultPageName,
layout: layout,
onHover: () async {
await renamePage(name);
@@ -331,7 +335,7 @@ extension CommonOperations on WidgetTester {
if (openAfterCreated) {
await openPage(
// if the name is null, use the default name
- name ?? LocaleKeys.menuAppHeader_defaultNewPageName.tr(),
+ name ?? defaultPageName,
layout: layout,
);
await pumpAndSettle();
@@ -368,7 +372,7 @@ extension CommonOperations on WidgetTester {
// hover on new created page and change it's name
await hoverOnPageName(
- LocaleKeys.menuAppHeader_defaultNewPageName.tr(),
+ '',
layout: layout,
onHover: () async {
await renamePage(pageName);
@@ -629,7 +633,11 @@ extension CommonOperations on WidgetTester {
expect(createWorkspaceDialog, findsOneWidget);
// input the workspace name
- await enterText(find.byType(TextField), name);
+ final workspaceNameInput = find.descendant(
+ of: createWorkspaceDialog,
+ matching: find.byType(TextField),
+ );
+ await enterText(workspaceNameInput, name);
await tapButtonWithName(LocaleKeys.button_ok.tr(), pumpAndSettle: false);
await pump(const Duration(seconds: 5));
diff --git a/frontend/appflowy_flutter/integration_test/shared/document_test_operations.dart b/frontend/appflowy_flutter/integration_test/shared/document_test_operations.dart
index d754519ffa..3f07f69101 100644
--- a/frontend/appflowy_flutter/integration_test/shared/document_test_operations.dart
+++ b/frontend/appflowy_flutter/integration_test/shared/document_test_operations.dart
@@ -7,7 +7,8 @@ import 'package:appflowy/plugins/document/presentation/editor_plugins/actions/bl
import 'package:appflowy/plugins/document/presentation/editor_plugins/actions/block_action_option_button.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/actions/drag_to_reorder/draggable_option_button.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/header/cover_editor.dart';
-import 'package:appflowy/plugins/document/presentation/editor_plugins/header/document_header_node_widget.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/header/cover_title.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/header/document_cover_widget.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/header/emoji_icon_widget.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/upload_image_menu/widgets/embed_image_url_widget.dart';
import 'package:appflowy/plugins/inline_actions/widgets/inline_actions_handler.dart';
@@ -323,4 +324,27 @@ class EditorOperations {
);
await tester.pumpAndSettle(Durations.short1);
}
+
+ Finder findDocumentTitle(String title) {
+ return find.descendant(
+ of: find.byType(CoverTitle),
+ matching: find.byWidgetPredicate(
+ (widget) {
+ if (widget is! TextField) {
+ return false;
+ }
+
+ if (widget.controller?.text == title) {
+ return true;
+ }
+
+ if (title.isEmpty) {
+ return widget.controller?.text.isEmpty ?? false;
+ }
+
+ return false;
+ },
+ ),
+ );
+ }
}
diff --git a/frontend/appflowy_flutter/integration_test/shared/expectation.dart b/frontend/appflowy_flutter/integration_test/shared/expectation.dart
index dedb2136f1..242e1ca1b2 100644
--- a/frontend/appflowy_flutter/integration_test/shared/expectation.dart
+++ b/frontend/appflowy_flutter/integration_test/shared/expectation.dart
@@ -2,7 +2,7 @@ import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/presentation/page_item/mobile_view_item.dart';
import 'package:appflowy/plugins/database/widgets/row/row_detail.dart';
import 'package:appflowy/plugins/document/presentation/banner.dart';
-import 'package:appflowy/plugins/document/presentation/editor_plugins/header/document_header_node_widget.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/header/document_cover_widget.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/header/emoji_icon_widget.dart';
import 'package:appflowy/workspace/application/sidebar/folder/folder_bloc.dart';
import 'package:appflowy/workspace/presentation/home/home_stack.dart';
diff --git a/frontend/appflowy_flutter/lib/plugins/document/application/document_bloc.dart b/frontend/appflowy_flutter/lib/plugins/document/application/document_bloc.dart
index 48d1000880..026f08442f 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/application/document_bloc.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/application/document_bloc.dart
@@ -270,9 +270,9 @@ class DocumentBloc extends Bloc<DocumentEvent, DocumentState> {
editorState.logConfiguration
..level = AppFlowyEditorLogLevel.all
..handler = (log) {
- if (enableDocumentInternalLog) {
- Log.info(log);
- }
+ // if (enableDocumentInternalLog) {
+ Log.info(log);
+ // }
};
}
diff --git a/frontend/appflowy_flutter/lib/plugins/document/document_page.dart b/frontend/appflowy_flutter/lib/plugins/document/document_page.dart
index 92807f715a..68c63419a2 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/document_page.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/document_page.dart
@@ -11,6 +11,7 @@ import 'package:appflowy/plugins/document/presentation/editor_plugins/cover/docu
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/custom_image_block_component/custom_image_block_component.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/multi_image_block_component/multi_image_block_component.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/shared_context/shared_context.dart';
import 'package:appflowy/plugins/document/presentation/editor_style.dart';
import 'package:appflowy/shared/flowy_error_page.dart';
import 'package:appflowy/shared/patterns/file_type_patterns.dart';
@@ -244,6 +245,8 @@ class _DocumentPageState extends State<DocumentPage>
},
child: AppFlowyEditorPage(
editorState: state.editorState!,
+ // if the view's name is empty, focus on the title
+ autoFocus: widget.view.name.isEmpty ? false : null,
styleCustomizer: EditorStyleCustomizer(
context: context,
width: width,
@@ -255,11 +258,14 @@ class _DocumentPageState extends State<DocumentPage>
);
}
- return Column(
- children: [
- if (state.isDeleted) _buildBanner(context),
- Expanded(child: child),
- ],
+ return Provider(
+ create: (_) => SharedEditorContext(),
+ child: Column(
+ children: [
+ if (state.isDeleted) _buildBanner(context),
+ Expanded(child: child),
+ ],
+ ),
);
}
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dart
index ec0f540ccb..3f7c2845e8 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dart
@@ -51,6 +51,9 @@ final localizedCodeBlockCommands =
codeBlockCommands(localizations: codeBlockLocalization);
final List<CommandShortcutEvent> commandShortcutEvents = [
+ backspaceToTitle,
+ arrowUpToTitle,
+ arrowLeftToTitle,
toggleToggleListCommand,
...localizedCodeBlockCommands,
customCopyCommand,
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/base/cover_title_command.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/base/cover_title_command.dart
new file mode 100644
index 0000000000..ac518dc65e
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/base/cover_title_command.dart
@@ -0,0 +1,132 @@
+import 'package:appflowy/plugins/document/presentation/editor_plugins/shared_context/shared_context.dart';
+import 'package:appflowy_editor/appflowy_editor.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter_bloc/flutter_bloc.dart';
+
+/// Press the backspace at the first position of first line to go to the title
+///
+/// - support
+/// - desktop
+/// - web
+///
+final CommandShortcutEvent backspaceToTitle = CommandShortcutEvent(
+ key: 'backspace to title',
+ command: 'backspace',
+ getDescription: () => 'backspace to title',
+ handler: (editorState) => _backspaceToTitle(
+ editorState: editorState,
+ ),
+);
+
+KeyEventResult _backspaceToTitle({
+ required EditorState editorState,
+}) {
+ final coverTitleFocusNode = editorState.document.root.context
+ ?.read<SharedEditorContext>()
+ .coverTitleFocusNode;
+ if (coverTitleFocusNode == null) {
+ return KeyEventResult.ignored;
+ }
+
+ final selection = editorState.selection;
+ // only active when the backspace is at the first position of first line
+ if (selection == null ||
+ !selection.isCollapsed ||
+ !selection.start.path.equals([0]) ||
+ selection.start.offset != 0) {
+ return KeyEventResult.ignored;
+ }
+
+ final node = editorState.getNodeAtPath(selection.end.path);
+ if (node == null || node.type != ParagraphBlockKeys.type) {
+ return KeyEventResult.ignored;
+ }
+
+ // delete the first line
+ () async {
+ // only delete the first line if it is empty
+ if (node.delta == null || node.delta!.isEmpty) {
+ final transaction = editorState.transaction;
+ transaction.deleteNode(node);
+ transaction.afterSelection = null;
+ await editorState.apply(transaction);
+ }
+
+ editorState.selection = null;
+ coverTitleFocusNode.requestFocus();
+ }();
+
+ return KeyEventResult.handled;
+}
+
+/// Press the arrow left at the first position of first line to go to the title
+///
+/// - support
+/// - desktop
+/// - web
+///
+final CommandShortcutEvent arrowLeftToTitle = CommandShortcutEvent(
+ key: 'arrow left to title',
+ command: 'arrow left',
+ getDescription: () => 'arrow left to title',
+ handler: (editorState) => _arrowKeyToTitle(
+ editorState: editorState,
+ checkSelection: (selection) {
+ if (!selection.isCollapsed ||
+ !selection.start.path.equals([0]) ||
+ selection.start.offset != 0) {
+ return false;
+ }
+ return true;
+ },
+ ),
+);
+
+/// Press the arrow up at the first line to go to the title
+///
+/// - support
+/// - desktop
+/// - web
+///
+final CommandShortcutEvent arrowUpToTitle = CommandShortcutEvent(
+ key: 'arrow up to title',
+ command: 'arrow up',
+ getDescription: () => 'arrow up to title',
+ handler: (editorState) => _arrowKeyToTitle(
+ editorState: editorState,
+ checkSelection: (selection) {
+ if (!selection.isCollapsed || !selection.start.path.equals([0])) {
+ return false;
+ }
+ return true;
+ },
+ ),
+);
+
+KeyEventResult _arrowKeyToTitle({
+ required EditorState editorState,
+ required bool Function(Selection selection) checkSelection,
+}) {
+ final coverTitleFocusNode = editorState.document.root.context
+ ?.read<SharedEditorContext>()
+ .coverTitleFocusNode;
+ if (coverTitleFocusNode == null) {
+ return KeyEventResult.ignored;
+ }
+
+ final selection = editorState.selection;
+ // only active when the arrow up is at the first line
+ if (selection == null || !checkSelection(selection)) {
+ return KeyEventResult.ignored;
+ }
+
+ final node = editorState.getNodeAtPath(selection.end.path);
+ if (node == null) {
+ return KeyEventResult.ignored;
+ }
+
+ editorState.selection = null;
+ coverTitleFocusNode.requestFocus();
+
+ return KeyEventResult.handled;
+}
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/header/cover_editor_bloc.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/header/cover_editor_bloc.dart
index 85633132d7..112cfda026 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/header/cover_editor_bloc.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/header/cover_editor_bloc.dart
@@ -2,7 +2,7 @@ import 'dart:async';
import 'dart:io';
import 'package:appflowy/plugins/document/presentation/editor_plugins/header/cover_editor.dart';
-import 'package:appflowy/plugins/document/presentation/editor_plugins/header/document_header_node_widget.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/header/document_cover_widget.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/header/cover_title.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/header/cover_title.dart
new file mode 100644
index 0000000000..33a48cad04
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/header/cover_title.dart
@@ -0,0 +1,235 @@
+import 'package:appflowy/generated/locale_keys.g.dart';
+import 'package:appflowy/plugins/document/application/document_appearance_cubit.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/shared_context/shared_context.dart';
+import 'package:appflowy/workspace/application/appearance_defaults.dart';
+import 'package:appflowy/workspace/application/view/view_bloc.dart';
+import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
+import 'package:appflowy_editor/appflowy_editor.dart';
+import 'package:easy_localization/easy_localization.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
+import 'package:flutter_bloc/flutter_bloc.dart';
+
+class CoverTitle extends StatelessWidget {
+ const CoverTitle({
+ super.key,
+ required this.view,
+ required this.offset,
+ });
+
+ final ViewPB view;
+ final double offset;
+
+ @override
+ Widget build(BuildContext context) {
+ return BlocProvider(
+ create: (context) => ViewBloc(view: view)..add(const ViewEvent.initial()),
+ child: _InnerCoverTitle(
+ view: view,
+ offset: offset,
+ ),
+ );
+ }
+}
+
+class _InnerCoverTitle extends StatefulWidget {
+ const _InnerCoverTitle({
+ required this.view,
+ required this.offset,
+ });
+
+ final ViewPB view;
+ final double offset;
+
+ @override
+ State<_InnerCoverTitle> createState() => _InnerCoverTitleState();
+}
+
+class _InnerCoverTitleState extends State<_InnerCoverTitle> {
+ final titleTextController = TextEditingController();
+ final titleFocusNode = FocusNode();
+ late final editorContext = context.read<SharedEditorContext>();
+ late final editorState = context.read<EditorState>();
+
+ @override
+ void initState() {
+ super.initState();
+
+ titleTextController.text = widget.view.name;
+ titleTextController.addListener(_onViewNameChanged);
+ titleFocusNode.onKeyEvent = _onKeyEvent;
+ titleFocusNode.addListener(() {
+ if (titleFocusNode.hasFocus && editorState.selection != null) {
+ editorState.selection = null;
+ }
+ });
+ _requestFocusIfNeeded(widget.view, null);
+
+ editorContext.coverTitleFocusNode = titleFocusNode;
+ }
+
+ @override
+ void dispose() {
+ editorContext.coverTitleFocusNode = null;
+
+ titleTextController.dispose();
+ titleFocusNode.dispose();
+
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final fontStyle = Theme.of(context)
+ .textTheme
+ .bodyMedium!
+ .copyWith(fontSize: 38.0, fontWeight: FontWeight.w700);
+ return BlocConsumer<ViewBloc, ViewState>(
+ listener: _onListen,
+ builder: (context, state) {
+ final appearance = context.read<DocumentAppearanceCubit>().state;
+ return Container(
+ padding: EdgeInsets.symmetric(horizontal: widget.offset),
+ child: Theme(
+ data: Theme.of(context).copyWith(
+ textSelectionTheme: TextSelectionThemeData(
+ cursorColor: appearance.selectionColor,
+ selectionColor: appearance.selectionColor ??
+ DefaultAppearanceSettings.getDefaultSelectionColor(context),
+ ),
+ ),
+ child: TextField(
+ controller: titleTextController,
+ focusNode: titleFocusNode,
+ maxLines: null,
+ style: fontStyle,
+ decoration: InputDecoration(
+ border: InputBorder.none,
+ hintText: LocaleKeys.menuAppHeader_defaultNewPageName.tr(),
+ hintStyle: fontStyle.copyWith(
+ color: Theme.of(context).hintColor,
+ ),
+ ),
+ ),
+ ),
+ );
+ },
+ );
+ }
+
+ void _onListen(BuildContext context, ViewState state) {
+ _requestFocusIfNeeded(widget.view, state);
+
+ if (state.view.name != titleTextController.text) {
+ titleTextController.text = state.view.name;
+ }
+ }
+
+ bool _shouldFocus(ViewPB view, ViewState? state) {
+ final name = state?.view.name ?? view.name;
+
+ // if the view's name is empty, focus on the title
+ if (name.isEmpty) {
+ return true;
+ }
+
+ return false;
+ }
+
+ void _requestFocusIfNeeded(ViewPB view, ViewState? state) {
+ final shouldFocus = _shouldFocus(view, state);
+ if (shouldFocus) {
+ titleFocusNode.requestFocus();
+ }
+ }
+
+ void _onViewNameChanged() {
+ Debounce.debounce(
+ 'update view name',
+ const Duration(milliseconds: 250),
+ () {
+ if (!mounted) {
+ return;
+ }
+ if (context.read<ViewBloc>().state.view.name !=
+ titleTextController.text) {
+ context
+ .read<ViewBloc>()
+ .add(ViewEvent.rename(titleTextController.text));
+ }
+ },
+ );
+ }
+
+ KeyEventResult _onKeyEvent(FocusNode focusNode, KeyEvent event) {
+ if (event.logicalKey == LogicalKeyboardKey.enter) {
+ // if enter is pressed, jump the first line of editor.
+ _createNewLine();
+ return KeyEventResult.handled;
+ } else if (event.logicalKey == LogicalKeyboardKey.arrowDown) {
+ return _moveCursorToNextLine(event.logicalKey);
+ } else if (event.logicalKey == LogicalKeyboardKey.arrowRight) {
+ return _moveCursorToNextLine(event.logicalKey);
+ }
+
+ return KeyEventResult.ignored;
+ }
+
+ Future<void> _createNewLine() async {
+ titleFocusNode.unfocus();
+
+ final selection = titleTextController.selection;
+ final text = titleTextController.text;
+ // split the text into two lines based on the cursor position
+ final parts = [
+ text.substring(0, selection.baseOffset),
+ text.substring(selection.baseOffset),
+ ];
+ titleTextController.text = parts[0];
+
+ final transaction = editorState.transaction;
+ transaction.insertNode([0], paragraphNode(text: parts[1]));
+ await editorState.apply(transaction);
+
+ // update selection instead of using afterSelection in transaction,
+ // because it will cause the cursor to jump
+ await editorState.updateSelectionWithReason(
+ Selection.collapsed(Position(path: [0])),
+ // trigger the keyboard service.
+ reason: SelectionUpdateReason.uiEvent,
+ );
+ }
+
+ KeyEventResult _moveCursorToNextLine(LogicalKeyboardKey key) {
+ final selection = titleTextController.selection;
+ final text = titleTextController.text;
+
+ // if the cursor is not at the end of the text, ignore the event
+ if (!selection.isCollapsed || text.length != selection.extentOffset) {
+ return KeyEventResult.ignored;
+ }
+
+ final node = editorState.getNodeAtPath([0]);
+ if (node == null) {
+ _createNewLine();
+ return KeyEventResult.handled;
+ }
+
+ titleFocusNode.unfocus();
+
+ int offset = 0;
+ if (key == LogicalKeyboardKey.arrowDown) {
+ offset = node.delta?.length ?? 0;
+ } else if (key == LogicalKeyboardKey.arrowRight) {
+ offset = 0;
+ }
+ editorState.updateSelectionWithReason(
+ Selection.collapsed(
+ Position(path: [0], offset: offset),
+ ),
+ // trigger the keyboard service.
+ reason: SelectionUpdateReason.uiEvent,
+ );
+ return KeyEventResult.handled;
+ }
+}
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/header/document_header_node_widget.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/header/document_cover_widget.dart
similarity index 89%
rename from frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/header/document_header_node_widget.dart
rename to frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/header/document_cover_widget.dart
index 8a0742f046..60dce56e99 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/header/document_header_node_widget.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/header/document_cover_widget.dart
@@ -1,8 +1,6 @@
import 'dart:io';
import 'dart:math';
-import 'package:flutter/material.dart';
-
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/application/page_style/document_page_style_bloc.dart';
@@ -27,12 +25,15 @@ import 'package:appflowy_popover/appflowy_popover.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flowy_infra_ui/widget/rounded_button.dart';
+import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
import 'package:string_validator/string_validator.dart';
import 'package:universal_platform/universal_platform.dart';
-const double kCoverHeight = 250.0;
+import 'cover_title.dart';
+
+const double kCoverHeight = 280.0;
const double kIconHeight = 60.0;
const double kToolbarHeight = 40.0; // with padding to the top
@@ -99,6 +100,9 @@ class _DocumentCoverWidgetState extends State<DocumentCoverWidget> {
late final ViewListener viewListener;
int retryCount = 0;
+ final titleTextController = TextEditingController();
+ final titleFocusNode = FocusNode();
+
@override
void initState() {
super.initState();
@@ -106,14 +110,21 @@ class _DocumentCoverWidgetState extends State<DocumentCoverWidget> {
viewIcon = value.isNotEmpty ? value : icon ?? '';
cover = widget.view.cover;
view = widget.view;
+ titleTextController.text = view.name;
widget.node.addListener(_reload);
+
viewListener = ViewListener(viewId: widget.view.id)
..start(
- onViewUpdated: (view) => setState(() {
- viewIcon = view.icon.value;
- cover = view.cover;
- view = view;
- }),
+ onViewUpdated: (view) {
+ if (titleTextController.text != view.name) {
+ titleTextController.text = view.name;
+ }
+ setState(() {
+ viewIcon = view.icon.value;
+ cover = view.cover;
+ view = view;
+ });
+ },
);
}
@@ -121,6 +132,8 @@ class _DocumentCoverWidgetState extends State<DocumentCoverWidget> {
void dispose() {
viewListener.stop();
widget.node.removeListener(_reload);
+ titleTextController.dispose();
+ titleFocusNode.dispose();
super.dispose();
}
@@ -129,43 +142,56 @@ class _DocumentCoverWidgetState extends State<DocumentCoverWidget> {
return LayoutBuilder(
builder: (context, constraints) {
final offset = _calculateIconLeft(context, constraints);
- return Stack(
+ return Column(
+ mainAxisSize: MainAxisSize.min,
children: [
- SizedBox(
- height: _calculateOverallHeight(),
- child: DocumentHeaderToolbar(
- onIconOrCoverChanged: _saveIconOrCover,
- node: widget.node,
- editorState: widget.editorState,
- hasCover: hasCover,
- hasIcon: hasIcon,
- offset: offset,
- ),
+ Stack(
+ children: [
+ SizedBox(
+ height: _calculateOverallHeight(),
+ child: DocumentHeaderToolbar(
+ onIconOrCoverChanged: _saveIconOrCover,
+ node: widget.node,
+ editorState: widget.editorState,
+ hasCover: hasCover,
+ hasIcon: hasIcon,
+ offset: offset,
+ ),
+ ),
+ if (hasCover)
+ DocumentCover(
+ view: view,
+ editorState: widget.editorState,
+ node: widget.node,
+ coverType: coverType,
+ coverDetails: coverDetails,
+ onChangeCover: (type, details) =>
+ _saveIconOrCover(cover: (type, details)),
+ ),
+ // don't render the icon if the offset is 0
+ if (hasIcon && offset != 0)
+ Positioned(
+ left: offset,
+ // if hasCover, there shouldn't be icons present so the icon can
+ // be closer to the bottom.
+ bottom: hasCover
+ ? kToolbarHeight - kIconHeight / 2
+ : kToolbarHeight,
+ child: DocumentIcon(
+ editorState: widget.editorState,
+ node: widget.node,
+ icon: viewIcon,
+ onChangeIcon: (icon) => _saveIconOrCover(icon: icon),
+ ),
+ ),
+ ],
),
- if (hasCover)
- DocumentCover(
- view: view,
- editorState: widget.editorState,
- node: widget.node,
- coverType: coverType,
- coverDetails: coverDetails,
- onChangeCover: (type, details) =>
- _saveIconOrCover(cover: (type, details)),
- ),
- // don't render the icon if the offset is 0
- if (hasIcon && offset != 0)
- Positioned(
- left: offset,
- // if hasCover, there shouldn't be icons present so the icon can
- // be closer to the bottom.
- bottom: hasCover
- ? kToolbarHeight - kIconHeight / 2
- : kToolbarHeight,
- child: DocumentIcon(
- editorState: widget.editorState,
- node: widget.node,
- icon: viewIcon,
- onChangeIcon: (icon) => _saveIconOrCover(icon: icon),
+ if (offset != 0)
+ Padding(
+ padding: const EdgeInsets.only(bottom: 12.0),
+ child: CoverTitle(
+ view: widget.view,
+ offset: offset,
),
),
],
@@ -210,16 +236,14 @@ class _DocumentCoverWidgetState extends State<DocumentCoverWidget> {
}
double _calculateOverallHeight() {
- switch ((hasIcon, hasCover)) {
- case (true, true):
- return kCoverHeight + kToolbarHeight;
- case (true, false):
- return 50 + kIconHeight + kToolbarHeight;
- case (false, true):
- return kCoverHeight + kToolbarHeight;
- case (false, false):
- return kToolbarHeight;
- }
+ final height = switch ((hasIcon, hasCover)) {
+ (true, true) => kCoverHeight + kToolbarHeight,
+ (true, false) => 50 + kIconHeight + kToolbarHeight,
+ (false, true) => kCoverHeight + kToolbarHeight,
+ (false, false) => kToolbarHeight,
+ };
+
+ return height;
}
void _saveIconOrCover({(CoverType, String?)? cover, String? icon}) async {
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/plugins.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/plugins.dart
index 05a509ddec..3e69374476 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/plugins.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/plugins.dart
@@ -1,6 +1,8 @@
export 'actions/block_action_list.dart';
export 'actions/option_action.dart';
export 'align_toolbar_item/align_toolbar_item.dart';
+export 'base/backtick_character_command.dart';
+export 'base/cover_title_command.dart';
export 'base/toolbar_extension.dart';
export 'bulleted_list/bulleted_list_icon.dart';
export 'callout/callout_block_component.dart';
@@ -20,7 +22,7 @@ export 'find_and_replace/find_and_replace_menu.dart';
export 'font/customize_font_toolbar_item.dart';
export 'header/cover_editor_bloc.dart';
export 'header/custom_cover_picker.dart';
-export 'header/document_header_node_widget.dart';
+export 'header/document_cover_widget.dart';
export 'heading/heading_toolbar_item.dart';
export 'image/custom_image_block_component/image_menu.dart';
export 'image/image_selection_menu.dart';
@@ -58,4 +60,3 @@ export 'table/table_option_action.dart';
export 'todo_list/todo_list_icon.dart';
export 'toggle/toggle_block_component.dart';
export 'toggle/toggle_block_shortcut_event.dart';
-export 'base/backtick_character_command.dart';
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/shared_context/shared_context.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/shared_context/shared_context.dart
new file mode 100644
index 0000000000..36c75af37d
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/shared_context/shared_context.dart
@@ -0,0 +1,13 @@
+import 'package:flutter/widgets.dart';
+
+/// Shared context for the editor plugins.
+///
+/// For example, the backspace command requires the focus node of the cover title.
+/// so we need to use the shared context to get the focus node.
+class SharedEditorContext {
+ SharedEditorContext();
+
+ // The focus node of the cover title.
+ // It's null when the cover title is not focused.
+ FocusNode? coverTitleFocusNode;
+}
diff --git a/frontend/appflowy_flutter/lib/workspace/application/sidebar/space/space_bloc.dart b/frontend/appflowy_flutter/lib/workspace/application/sidebar/space/space_bloc.dart
index d612f4d688..98e031b987 100644
--- a/frontend/appflowy_flutter/lib/workspace/application/sidebar/space/space_bloc.dart
+++ b/frontend/appflowy_flutter/lib/workspace/application/sidebar/space/space_bloc.dart
@@ -3,7 +3,6 @@ import 'dart:convert';
import 'package:appflowy/core/config/kv.dart';
import 'package:appflowy/core/config/kv_keys.dart';
-import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/shared/list_extension.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/user/application/user_service.dart';
@@ -19,7 +18,6 @@ import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart';
import 'package:appflowy_result/appflowy_result.dart';
import 'package:collection/collection.dart';
-import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra/uuid.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
@@ -129,8 +127,8 @@ class SpaceBloc extends Bloc<SpaceEvent, SpaceState> {
if (createNewPageByDefault) {
add(
- SpaceEvent.createPage(
- name: LocaleKeys.menuAppHeader_defaultNewPageName.tr(),
+ const SpaceEvent.createPage(
+ name: '',
index: 0,
layout: ViewLayoutPB.Document,
),
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/folder/_section_folder.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/folder/_section_folder.dart
index c957a664c2..e9a4b99460 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/folder/_section_folder.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/folder/_section_folder.dart
@@ -85,22 +85,20 @@ class _SectionFolderState extends State<SectionFolder> {
createViewAndShowRenameDialogIfNeeded(
context,
LocaleKeys.newPageText.tr(),
- (viewName, _) {
- if (viewName.isNotEmpty) {
- context.read<SidebarSectionsBloc>().add(
- SidebarSectionsEvent.createRootViewInSection(
- name: viewName,
- index: 0,
- viewSection: widget.spaceType.toViewSectionPB,
- ),
- );
+ (_, __) {
+ context.read<SidebarSectionsBloc>().add(
+ SidebarSectionsEvent.createRootViewInSection(
+ name: '',
+ index: 0,
+ viewSection: widget.spaceType.toViewSectionPB,
+ ),
+ );
- context.read<FolderBloc>().add(
- const FolderEvent.expandOrUnExpand(
- isExpanded: true,
- ),
- );
- }
+ context.read<FolderBloc>().add(
+ const FolderEvent.expandOrUnExpand(
+ isExpanded: true,
+ ),
+ );
},
);
},
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/shared/rename_view_dialog.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/shared/rename_view_dialog.dart
index bf18df1a98..e8fec96e9b 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/shared/rename_view_dialog.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/shared/rename_view_dialog.dart
@@ -22,14 +22,15 @@ Future<void> createViewAndShowRenameDialogIfNeeded(
(value) => bool.parse(value),
);
final showRenameDialog = value ?? false;
+ final defaultName = LocaleKeys.menuAppHeader_defaultNewPageName.tr();
if (context.mounted && showRenameDialog) {
await NavigatorTextFieldDialog(
title: dialogTitle,
- value: LocaleKeys.menuAppHeader_defaultNewPageName.tr(),
+ value: defaultName,
autoSelectAllText: true,
onConfirm: createView,
).show(context);
} else if (context.mounted) {
- createView(LocaleKeys.menuAppHeader_defaultNewPageName.tr(), context);
+ createView(defaultName, context);
}
}
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/shared/sidebar_new_page_button.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/shared/sidebar_new_page_button.dart
index 6fdd0d65b7..1358492eb1 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/shared/sidebar_new_page_button.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/shared/sidebar_new_page_button.dart
@@ -60,31 +60,29 @@ class _SidebarNewPageButtonState extends State<SidebarNewPageButton> {
return createViewAndShowRenameDialogIfNeeded(
context,
LocaleKeys.newPageText.tr(),
- (viewName, _) {
- if (viewName.isNotEmpty) {
- // if the workspace is collaborative, create the view in the private section by default.
- final section =
- context.read<UserWorkspaceBloc>().state.isCollabWorkspaceOn
- ? ViewSectionPB.Private
- : ViewSectionPB.Public;
- final spaceState = context.read<SpaceBloc>().state;
- if (spaceState.spaces.isNotEmpty) {
- context.read<SpaceBloc>().add(
- SpaceEvent.createPage(
- name: viewName,
- index: 0,
- layout: ViewLayoutPB.Document,
- ),
- );
- } else {
- context.read<SidebarSectionsBloc>().add(
- SidebarSectionsEvent.createRootViewInSection(
- name: viewName,
- viewSection: section,
- index: 0,
- ),
- );
- }
+ (_, __) {
+ // if the workspace is collaborative, create the view in the private section by default.
+ final section =
+ context.read<UserWorkspaceBloc>().state.isCollabWorkspaceOn
+ ? ViewSectionPB.Private
+ : ViewSectionPB.Public;
+ final spaceState = context.read<SpaceBloc>().state;
+ if (spaceState.spaces.isNotEmpty) {
+ context.read<SpaceBloc>().add(
+ const SpaceEvent.createPage(
+ name: '',
+ index: 0,
+ layout: ViewLayoutPB.Document,
+ ),
+ );
+ } else {
+ context.read<SidebarSectionsBloc>().add(
+ SidebarSectionsEvent.createRootViewInSection(
+ name: '',
+ viewSection: section,
+ index: 0,
+ ),
+ );
}
},
);
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/space/sidebar_space.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/space/sidebar_space.dart
index 288f42c064..c6e5098d07 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/space/sidebar_space.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/space/sidebar_space.dart
@@ -1,4 +1,3 @@
-import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/workspace/application/favorite/favorite_bloc.dart';
import 'package:appflowy/workspace/application/sidebar/space/space_bloc.dart';
@@ -13,7 +12,6 @@ import 'package:appflowy/workspace/presentation/home/menu/sidebar/space/sidebar_
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart';
import 'package:appflowy_editor/appflowy_editor.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/services.dart';
@@ -167,7 +165,7 @@ class _SpaceState extends State<_Space> {
) {
context.read<SpaceBloc>().add(
SpaceEvent.createPage(
- name: LocaleKeys.menuAppHeader_defaultNewPageName.tr(),
+ name: '',
layout: layout,
index: 0,
),
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/space/sidebar_space_header.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/space/sidebar_space_header.dart
index 6824058f1a..14d77e9da9 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/space/sidebar_space_header.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/space/sidebar_space_header.dart
@@ -1,7 +1,5 @@
import 'dart:io';
-import 'package:flutter/material.dart' hide Icon;
-
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/shared/icon_emoji_picker/icon.dart';
import 'package:appflowy/workspace/application/sidebar/space/space_bloc.dart';
@@ -15,6 +13,7 @@ import 'package:appflowy/workspace/presentation/widgets/dialogs.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
+import 'package:flutter/material.dart' hide Icon;
import 'package:flutter_bloc/flutter_bloc.dart';
class SidebarSpaceHeader extends StatefulWidget {
@@ -149,6 +148,9 @@ class _SidebarSpaceHeaderState extends State<SidebarSpaceHeader> {
openAfterCreated,
createNewView,
) {
+ if (pluginBuilder.layoutType == ViewLayoutPB.Document) {
+ name = '';
+ }
if (createNewView) {
widget.onAdded(pluginBuilder.layoutType!);
}
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/view/view_item.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/view/view_item.dart
index ac96ece98f..69772a83e0 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/view/view_item.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/view/view_item.dart
@@ -3,6 +3,7 @@ import 'dart:async';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/shared/icon_emoji_picker/flowy_icon_emoji_picker.dart';
+import 'package:appflowy/startup/plugin/plugin.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/workspace/application/favorite/favorite_bloc.dart';
import 'package:appflowy/workspace/application/sidebar/folder/folder_bloc.dart';
@@ -515,7 +516,9 @@ class _SingleInnerViewItemState extends State<SingleInnerViewItem> {
Widget _buildViewItem(bool onHover, [bool isSelected = false]) {
final name = FlowyText.regular(
- widget.view.name,
+ widget.view.name.isEmpty
+ ? LocaleKeys.menuAppHeader_defaultNewPageName.tr()
+ : widget.view.name,
overflow: TextOverflow.ellipsis,
fontSize: 14.0,
figmaLineHeight: 18.0,
@@ -650,43 +653,49 @@ class _SingleInnerViewItemState extends State<SingleInnerViewItem> {
// + button
Widget _buildViewAddButton(BuildContext context) {
- final viewBloc = context.read<ViewBloc>();
return FlowyTooltip(
message: LocaleKeys.menuAppHeader_addPageTooltip.tr(),
child: ViewAddButton(
parentViewId: widget.view.id,
onEditing: (value) =>
context.read<ViewBloc>().add(ViewEvent.setIsEditing(value)),
- onSelected: (
- pluginBuilder,
- name,
- initialDataBytes,
- openAfterCreated,
- createNewView,
- ) {
- if (createNewView) {
- createViewAndShowRenameDialogIfNeeded(
- context,
- _convertLayoutToHintText(pluginBuilder.layoutType!),
- (viewName, _) {
- if (viewName.isNotEmpty) {
- viewBloc.add(
- ViewEvent.createView(
- viewName,
- pluginBuilder.layoutType!,
- openAfterCreated: openAfterCreated,
- section: widget.spaceType.toViewSectionPB,
- ),
- );
- }
- },
- );
+ onSelected: _onSelected,
+ ),
+ );
+ }
+
+ void _onSelected(
+ PluginBuilder pluginBuilder,
+ String? name,
+ List<int>? initialDataBytes,
+ bool openAfterCreated,
+ bool createNewView,
+ ) {
+ final viewBloc = context.read<ViewBloc>();
+
+ if (createNewView) {
+ createViewAndShowRenameDialogIfNeeded(
+ context,
+ _convertLayoutToHintText(pluginBuilder.layoutType!),
+ (viewName, _) {
+ // the name of new document should be empty
+ if (pluginBuilder.layoutType == ViewLayoutPB.Document) {
+ viewName = '';
}
viewBloc.add(
- const ViewEvent.setIsExpanded(true),
+ ViewEvent.createView(
+ viewName,
+ pluginBuilder.layoutType!,
+ openAfterCreated: openAfterCreated,
+ section: widget.spaceType.toViewSectionPB,
+ ),
);
},
- ),
+ );
+ }
+
+ viewBloc.add(
+ const ViewEvent.setIsExpanded(true),
);
}
diff --git a/frontend/appflowy_flutter/pubspec.lock b/frontend/appflowy_flutter/pubspec.lock
index 5c14ff904c..895140f52c 100644
--- a/frontend/appflowy_flutter/pubspec.lock
+++ b/frontend/appflowy_flutter/pubspec.lock
@@ -53,8 +53,8 @@ packages:
dependency: "direct main"
description:
path: "."
- ref: "8582191"
- resolved-ref: "8582191b0670ebccfb551b04c97d96d2f1c471fe"
+ ref: "737681d"
+ resolved-ref: "737681dd97b501dd88c7c016c5c359f9ffff7d31"
url: "https://github.com/AppFlowy-IO/appflowy-editor.git"
source: git
version: "3.3.0"
@@ -1559,10 +1559,10 @@ packages:
dependency: transitive
description:
name: platform
- sha256: "12220bb4b65720483f8fa9450b4332347737cf8213dd2840d8b2c823e47243ec"
+ sha256: "9b71283fc13df574056616011fb138fd3b793ea47cc509c189a6c3fa5f8a1a65"
url: "https://pub.dev"
source: hosted
- version: "3.1.4"
+ version: "3.1.5"
plugin_platform_interface:
dependency: "direct dev"
description:
@@ -1989,10 +1989,10 @@ packages:
dependency: transitive
description:
name: string_scanner
- sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde"
+ sha256: "688af5ed3402a4bde5b3a6c15fd768dbf2621a614950b17f04626c431ab3c4c3"
url: "https://pub.dev"
source: hosted
- version: "1.2.0"
+ version: "1.3.0"
string_validator:
dependency: "direct main"
description:
@@ -2311,10 +2311,10 @@ packages:
dependency: transitive
description:
name: vm_service
- sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec"
+ sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d"
url: "https://pub.dev"
source: hosted
- version: "14.2.1"
+ version: "14.2.5"
watcher:
dependency: transitive
description:
diff --git a/frontend/appflowy_flutter/pubspec.yaml b/frontend/appflowy_flutter/pubspec.yaml
index 1faf306777..1983d915ee 100644
--- a/frontend/appflowy_flutter/pubspec.yaml
+++ b/frontend/appflowy_flutter/pubspec.yaml
@@ -172,12 +172,12 @@ dependency_overrides:
url_protocol:
git:
url: https://github.com/LucasXu0/flutter_url_protocol.git
- commit: 77a8420
+ commit: 737681d
appflowy_editor:
git:
url: https://github.com/AppFlowy-IO/appflowy-editor.git
- ref: "8582191"
+ ref: "737681d"
appflowy_editor_plugins:
git: