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.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
fix: using the shortcut to show the search panel will hide the 'Ask AI anything' button (#7916)
Morncf14a37dcfac
diff --git a/frontend/appflowy_flutter/integration_test/desktop/cloud/cloud_runner.dart b/frontend/appflowy_flutter/integration_test/desktop/cloud/cloud_runner.dartindex ec40af8fb7..922649d08f 100644--- a/frontend/appflowy_flutter/integration_test/desktop/cloud/cloud_runner.dart+++ b/frontend/appflowy_flutter/integration_test/desktop/cloud/cloud_runner.dart@@ -4,6 +4,7 @@ import 'database/database_test_runner.dart' as database_test_runner;import 'document/document_test_runner.dart' as document_test_runner;import 'set_env.dart' as preset_af_cloud_env_test;import 'sidebar/sidebar_icon_test.dart' as sidebar_icon_test;+import 'sidebar/sidebar_search_test.dart' as sidebar_search_test;import 'sidebar/sidebar_move_page_test.dart' as sidebar_move_page_test;import 'sidebar/sidebar_rename_untitled_test.dart'as sidebar_rename_untitled_test;@@ -31,6 +32,7 @@ Future<void> main() async {sidebar_move_page_test.main();sidebar_rename_untitled_test.main();sidebar_icon_test.main();+ sidebar_search_test.main();}// databasediff --git a/frontend/appflowy_flutter/integration_test/desktop/cloud/sidebar/sidebar_search_test.dart b/frontend/appflowy_flutter/integration_test/desktop/cloud/sidebar/sidebar_search_test.dartnew file mode 100644index 0000000000..9e1ca27844--- /dev/null+++ b/frontend/appflowy_flutter/integration_test/desktop/cloud/sidebar/sidebar_search_test.dart@@ -0,0 +1,42 @@+import 'package:appflowy/ai/widgets/prompt_input/desktop_prompt_input.dart';+import 'package:appflowy/env/cloud_env.dart';+import 'package:appflowy/generated/locale_keys.g.dart';+import 'package:appflowy/workspace/presentation/command_palette/widgets/search_ask_ai_entrance.dart';+import 'package:appflowy/workspace/presentation/command_palette/widgets/search_field.dart';+import 'package:easy_localization/easy_localization.dart';+import 'package:flutter/material.dart';+import 'package:flutter_test/flutter_test.dart';+import 'package:integration_test/integration_test.dart';++import '../../../shared/util.dart';++void main() {+ setUpAll(() {+ IntegrationTestWidgetsFlutterBinding.ensureInitialized();+ });++ testWidgets('Test for searching', (tester) async {+ await tester.initializeAppFlowy(+ cloudType: AuthenticatorType.appflowyCloudSelfHost,+ );+ await tester.tapGoogleLoginInButton();+ await tester.expectToSeeHomePageWithGetStartedPage();++ /// show searching page+ final searchingButton = find.text(LocaleKeys.search_label.tr());+ await tester.tapButton(searchingButton);+ final askAIButton = find.byType(SearchAskAiEntrance);+ expect(askAIButton, findsOneWidget);++ /// searching for [gettingStarted]+ final searchField = find.byType(SearchField);+ final textFiled =+ find.descendant(of: searchField, matching: find.byType(TextField));+ await tester.enterText(textFiled, gettingStarted);+ await tester.pumpAndSettle(Duration(seconds: 1));++ /// tap ask AI button+ await tester.tapButton(askAIButton);+ expect(find.byType(DesktopPromptInput), findsOneWidget);+ });+}diff --git a/frontend/appflowy_flutter/integration_test/desktop/command_palette/command_palette_test.dart b/frontend/appflowy_flutter/integration_test/desktop/command_palette/command_palette_test.dartindex 7bf9a86966..117677b643 100644--- a/frontend/appflowy_flutter/integration_test/desktop/command_palette/command_palette_test.dart+++ b/frontend/appflowy_flutter/integration_test/desktop/command_palette/command_palette_test.dart@@ -1,7 +1,17 @@import 'package:appflowy/workspace/presentation/command_palette/command_palette.dart';+import 'package:appflowy/workspace/presentation/command_palette/widgets/search_ask_ai_entrance.dart';+import 'package:appflowy/workspace/presentation/command_palette/widgets/search_result_cell.dart';+import 'package:appflowy/workspace/presentation/home/menu/sidebar/sidebar.dart';import 'package:flutter_test/flutter_test.dart';import 'package:integration_test/integration_test.dart';-+import 'package:appflowy/generated/flowy_svgs.g.dart';+import 'package:appflowy/generated/locale_keys.g.dart';+import 'package:appflowy/workspace/presentation/command_palette/widgets/page_preview.dart';+import 'package:appflowy/workspace/presentation/command_palette/widgets/recent_views_list.dart';+import 'package:appflowy/workspace/presentation/command_palette/widgets/search_field.dart';+import 'package:appflowy/workspace/presentation/command_palette/widgets/search_results_list.dart';+import 'package:easy_localization/easy_localization.dart';+import 'package:flutter/material.dart';import '../../shared/util.dart';void main() {@@ -19,4 +29,70 @@ void main() {expect(find.byType(CommandPaletteModal), findsNothing);});});++ group('Search', () {+ testWidgets('Test for searching', (tester) async {+ await tester.initializeAppFlowy();+ await tester.tapAnonymousSignInButton();++ await tester.createNewPageWithNameUnderParent(name: 'Switch To New Page');+ await tester.pumpAndSettle();++ /// tap getting started page+ await tester.tapButton(+ find.descendant(+ of: find.byType(HomeSideBar),+ matching: find.textContaining(gettingStarted),+ ),+ );++ /// show searching page+ final searchingButton = find.text(LocaleKeys.search_label.tr());+ await tester.tapButton(searchingButton);+ final askAIButton = find.byType(SearchAskAiEntrance);+ expect(askAIButton, findsNothing);+ final recentList = find.byType(RecentViewsList);+ expect(recentList, findsOneWidget);++ /// there is [gettingStarted] in recent list+ final gettingStartedRecentCell = find.descendant(+ of: recentList,+ matching: find.textContaining(gettingStarted),+ );+ expect(gettingStartedRecentCell, findsAtLeast(1));++ /// hover to show preview+ await tester.hoverOnWidget(gettingStartedRecentCell.first);+ final pagePreview = find.byType(PagePreview);+ expect(pagePreview, findsOneWidget);+ final gettingStartedPreviewTitle = find.descendant(+ of: pagePreview,+ matching: find.textContaining(gettingStarted),+ );+ expect(gettingStartedPreviewTitle, findsOneWidget);++ /// searching for [gettingStarted]+ final searchField = find.byType(SearchField);+ final textFiled =+ find.descendant(of: searchField, matching: find.byType(TextField));+ await tester.enterText(textFiled, gettingStarted);+ await tester.pumpAndSettle(Duration(seconds: 1));++ /// there is [gettingStarted] in result list+ final resultList = find.byType(SearchResultList);+ expect(resultList, findsOneWidget);+ final resultCells = find.byType(SearchResultCell);+ expect(resultCells, findsAtLeast(1));++ /// hover to show preview+ await tester.hoverOnWidget(resultCells.first);+ expect(find.byType(PagePreview), findsOneWidget);++ /// clear search content+ final clearButton = find.byFlowySvg(FlowySvgs.search_clear_m);+ await tester.tapButton(clearButton);+ expect(find.byType(SearchResultList), findsNothing);+ expect(find.byType(RecentViewsList), findsOneWidget);+ });+ });}diff --git a/frontend/appflowy_flutter/lib/mobile/presentation/search/mobile_view_ancestors.dart b/frontend/appflowy_flutter/lib/mobile/presentation/search/mobile_view_ancestors.dartindex cd116d4ec9..7362211938 100644--- a/frontend/appflowy_flutter/lib/mobile/presentation/search/mobile_view_ancestors.dart+++ b/frontend/appflowy_flutter/lib/mobile/presentation/search/mobile_view_ancestors.dart@@ -1,5 +1,6 @@import 'package:appflowy/startup/startup.dart';import 'package:appflowy_ui/appflowy_ui.dart';+import 'package:flowy_infra_ui/widget/spacing.dart';import 'package:flutter/material.dart';import 'package:flutter_bloc/flutter_bloc.dart';import 'package:freezed_annotation/freezed_annotation.dart';@@ -20,6 +21,8 @@ class ViewAncestorBloc extends Bloc<ViewAncestorEvent, ViewAncestorState> {(event, emit) async {await event.map(initial: (e) async {+ emit(state.copyWith(isLoading: true));+final ancester = await _cache.getAncestor(state.viewId,onRefresh: (ancestor) {@@ -62,6 +65,8 @@ extension ViewAncestorTextExtension on ViewAncestorState {final ancestors = ancestor.ancestors;final textStyle = style ??theme.textStyle.caption.standard(color: theme.textColorScheme.tertiary);+ final textHeight = (textStyle.fontSize ?? 0.0) * (textStyle.height ?? 1.0);+ if (isLoading) return VSpace(textHeight);return LayoutBuilder(builder: (context, constrains) {final List<String> displayPath = ancestors.map((e) => e.name).toList();diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/command_palette.dart b/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/command_palette.dartindex 5665dc251f..bf7d43800f 100644--- a/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/command_palette.dart+++ b/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/command_palette.dart@@ -44,6 +44,9 @@ class CommandPalette extends InheritedWidget {return result!;}+ static CommandPalette? maybeOf(BuildContext context) =>+ context.dependOnInheritedWidgetOfExactType<CommandPalette>();+void toggle({UserWorkspaceBloc? workspaceBloc,SpaceBloc? spaceBloc,@@ -56,6 +59,16 @@ class CommandPalette extends InheritedWidget {);}+ void updateBlocs({+ UserWorkspaceBloc? workspaceBloc,+ SpaceBloc? spaceBloc,+ }) {+ notifier.value = notifier.value.copyWith(+ userWorkspaceBloc: workspaceBloc,+ spaceBloc: spaceBloc,+ );+ }+@overridebool updateShouldNotify(covariant InheritedWidget oldWidget) => false;}diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/page_preview.dart b/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/page_preview.dartindex 4d4bd9cef4..de54a6e8f1 100644--- a/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/page_preview.dart+++ b/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/page_preview.dart@@ -4,7 +4,6 @@ import 'package:appflowy/mobile/presentation/search/mobile_view_ancestors.dart';import 'package:appflowy/plugins/document/presentation/editor_plugins/header/emoji_icon_widget.dart';import 'package:appflowy/shared/icon_emoji_picker/flowy_icon_emoji_picker.dart';import 'package:appflowy/util/int64_extension.dart';-import 'package:appflowy/workspace/application/command_palette/search_result_list_bloc.dart';import 'package:appflowy/workspace/application/settings/appearance/appearance_cubit.dart';import 'package:appflowy/workspace/application/settings/date_time/date_format_ext.dart';import 'package:appflowy/workspace/application/view/view_ext.dart';@@ -16,8 +15,13 @@ import 'package:flutter/material.dart';import 'package:flutter_bloc/flutter_bloc.dart';class PagePreview extends StatelessWidget {- const PagePreview({super.key, required this.view});+ const PagePreview({+ super.key,+ required this.view,+ required this.onViewOpened,+ });final ViewPB view;+ final VoidCallback onViewOpened;@overrideWidget build(BuildContext context) {@@ -72,18 +76,29 @@ class PagePreview extends StatelessWidget {Widget buildTitle(BuildContext context, ViewPB view) {final theme = AppFlowyTheme.of(context);+ final titleStyle = theme.textStyle.heading4+ .enhanced(color: theme.textColorScheme.primary),+ titleHoverStyle =+ titleStyle.copyWith(decoration: TextDecoration.underline);return SizedBox(height: 28,child: Row(children: [Flexible(- child: Text(- view.nameOrDefault,- maxLines: 1,- overflow: TextOverflow.ellipsis,- style: theme.textStyle.heading4.enhanced(- color: theme.textColorScheme.primary,+ child: AFBaseButton(+ padding: EdgeInsets.zero,+ builder: (context, isHovering, disabled) =>+ SelectionContainer.disabled(+ child: Text(+ view.nameOrDefault,+ style: isHovering ? titleHoverStyle : titleStyle,+ maxLines: 1,+ overflow: TextOverflow.ellipsis,+ ),),+ borderColor: (_, __, ___, ____) => Colors.transparent,+ borderRadius: 0,+ onTap: onViewOpened,),),HSpace(4),@@ -92,11 +107,7 @@ class PagePreview extends StatelessWidget {child: AFGhostButton.normal(size: AFButtonSize.s,padding: EdgeInsets.all(theme.spacing.xs),- onTap: () {- context.read<SearchResultListBloc?>()?.add(- SearchResultListEvent.openPage(pageId: view.id),- );- },+ onTap: onViewOpened,builder: (context, isHovering, disabled) => FlowySvg(FlowySvgs.search_arrow_right_m,size: const Size.square(20),@@ -115,7 +126,8 @@ class PagePreview extends StatelessWidget {create: (context) => ViewAncestorBloc(view.id),child: BlocBuilder<ViewAncestorBloc, ViewAncestorState>(builder: (context, state) {- if (state.ancestor.ancestors.isEmpty) return const SizedBox.shrink();+ final isEmpty = state.ancestor.ancestors.isEmpty;+ if (!state.isLoading && isEmpty) return const SizedBox.shrink();return Column(crossAxisAlignment: CrossAxisAlignment.start,children: [diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/recent_views_list.dart b/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/recent_views_list.dartindex 13bd51b580..c49e1c93ee 100644--- a/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/recent_views_list.dart+++ b/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/recent_views_list.dart@@ -2,6 +2,9 @@ import 'package:appflowy/generated/flowy_svgs.g.dart';import 'package:appflowy/generated/locale_keys.g.dart';import 'package:appflowy/plugins/document/presentation/editor_plugins/header/emoji_icon_widget.dart';import 'package:appflowy/shared/icon_emoji_picker/flowy_icon_emoji_picker.dart';+import 'package:appflowy/startup/startup.dart';+import 'package:appflowy/workspace/application/action_navigation/action_navigation_bloc.dart';+import 'package:appflowy/workspace/application/action_navigation/navigation_action.dart';import 'package:appflowy/workspace/application/recent/recent_views_bloc.dart';import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';import 'package:appflowy/workspace/application/view/view_ext.dart';@@ -110,7 +113,20 @@ class RecentViewsList extends StatelessWidget {onSelected: onSelected,);},- separatorBuilder: (_, __) => AFDivider(),+ separatorBuilder: (_, index) {+ final view = recentViews[index];+ final isHovered =+ hoveredView?.id == view.id;+ if (isHovered) return VSpace(1);+ if (index < recentViews.length - 1) {+ final nextView =+ recentViews[index + 1];+ final isNextHovered =+ hoveredView?.id == nextView.id;+ if (isNextHovered) return VSpace(1);+ }+ return const AFDivider();+ },),VSpace(8),],@@ -126,7 +142,19 @@ class RecentViewsList extends StatelessWidget {Flexible(child: Align(alignment: Alignment.topLeft,- child: PagePreview(view: hoveredView),+ child: PagePreview(+ view: hoveredView,+ onViewOpened: () {+ getIt<ActionNavigationBloc>().add(+ ActionNavigationEvent.performAction(+ action: NavigationAction(+ objectId: hoveredView.id,+ ),+ ),+ );+ onSelected();+ },+ ),),),],diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/search_result_cell.dart b/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/search_result_cell.dartindex dad23581ff..eb7522530c 100644--- a/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/search_result_cell.dart+++ b/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/search_result_cell.dart@@ -226,7 +226,14 @@ class SearchResultPreview extends StatelessWidget {final view = snapshot.data?.toNullable();if (view == null) return SomethingWentWrong();- return PagePreview(view: view);+ return PagePreview(+ view: view,+ onViewOpened: () {+ context+ .read<SearchResultListBloc?>()+ ?.add(SearchResultListEvent.openPage(pageId: view.id));+ },+ );},);}diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/search_results_list.dart b/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/search_results_list.dartindex cc1649690d..d13d2e63b3 100644--- a/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/search_results_list.dart+++ b/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/search_results_list.dart@@ -107,47 +107,56 @@ class _SearchResultListState extends State<SearchResultList> {.toList();return ScrollControllerBuilder(builder: (context, controller) {+ final hoveredId = bloc.state.hoveredResult?.id;return FlowyScrollbar(controller: controller,child: SingleChildScrollView(controller: controller,physics: ClampingScrollPhysics(),- child: Flexible(- child: Column(- crossAxisAlignment: CrossAxisAlignment.start,- children: [- if (showAskingAI) SearchAskAiEntrance(),- Padding(- padding:- const EdgeInsets.symmetric(horizontal: 12, vertical: 8),- child: Column(- crossAxisAlignment: CrossAxisAlignment.start,- children: [- _buildSectionHeader(context),- VSpace(8),- ListView.separated(- physics: const NeverScrollableScrollPhysics(),- shrinkWrap: true,- itemCount: resultItems.length,- separatorBuilder: (_, __) => AFDivider(),- itemBuilder: (_, index) {- final item = resultItems[index];- return SearchResultCell(- item: item,- isHovered:- bloc.state.hoveredResult?.id == item.id,- query: context- .read<CommandPaletteBloc?>()- ?.state- .query,- );- },- ),- ],- ),+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ if (showAskingAI) SearchAskAiEntrance(),+ Padding(+ padding:+ const EdgeInsets.symmetric(horizontal: 12, vertical: 8),+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ mainAxisSize: MainAxisSize.min,+ children: [+ _buildSectionHeader(context),+ VSpace(8),+ ListView.separated(+ physics: const NeverScrollableScrollPhysics(),+ shrinkWrap: true,+ itemCount: resultItems.length,+ separatorBuilder: (_, index) {+ final item = resultItems[index];+ final isHovered = hoveredId == item.id;+ if (isHovered) return VSpace(1);+ if (index < resultItems.length - 1) {+ final nextView = resultItems[index + 1];+ final isNextHovered = hoveredId == nextView.id;+ if (isNextHovered) return VSpace(1);+ }+ return const AFDivider();+ },+ itemBuilder: (_, index) {+ final item = resultItems[index];+ return SearchResultCell(+ item: item,+ isHovered: hoveredId == item.id,+ query: context+ .read<CommandPaletteBloc?>()+ ?.state+ .query,+ );+ },+ ),+ ],),- ],- ),+ ),+ ],),),);diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/desktop_home_screen.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/desktop_home_screen.dartindex e36690934c..927f163746 100644--- a/frontend/appflowy_flutter/lib/workspace/presentation/home/desktop_home_screen.dart+++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/desktop_home_screen.dart@@ -8,10 +8,12 @@ import 'package:appflowy/workspace/application/favorite/favorite_bloc.dart';import 'package:appflowy/workspace/application/home/home_bloc.dart';import 'package:appflowy/workspace/application/home/home_setting_bloc.dart';import 'package:appflowy/workspace/application/settings/appearance/appearance_cubit.dart';+import 'package:appflowy/workspace/application/sidebar/space/space_bloc.dart';import 'package:appflowy/workspace/application/tabs/tabs_bloc.dart';import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';import 'package:appflowy/workspace/application/view/view_ext.dart';import 'package:appflowy/workspace/application/view/view_service.dart';+import 'package:appflowy/workspace/presentation/command_palette/command_palette.dart';import 'package:appflowy/workspace/presentation/home/af_focus_manager.dart';import 'package:appflowy/workspace/presentation/home/errors/workspace_failed_screen.dart';import 'package:appflowy/workspace/presentation/home/hotkeys.dart';@@ -127,14 +129,28 @@ class DesktopHomeScreen extends StatelessWidget {builder: (context, state) => BlocProvider(create: (_) => UserWorkspaceBloc(userProfile: userProfile)..add(const UserWorkspaceEvent.initial()),- child: HomeHotKeys(- userProfile: userProfile,- child: FlowyContainer(- Theme.of(context).colorScheme.surface,- child: _buildBody(- context,- userProfile,- workspaceLatest,+ child: BlocListener<UserWorkspaceBloc, UserWorkspaceState>(+ listenWhen: (previous, current) =>+ previous.currentWorkspace != current.currentWorkspace,+ listener: (context, state) {+ if (!context.mounted) return;+ final workspaceBloc =+ context.read<UserWorkspaceBloc?>();+ final spaceBloc = context.read<SpaceBloc?>();+ CommandPalette.maybeOf(context)?.updateBlocs(+ workspaceBloc: workspaceBloc,+ spaceBloc: spaceBloc,+ );+ },+ child: HomeHotKeys(+ userProfile: userProfile,+ child: FlowyContainer(+ Theme.of(context).colorScheme.surface,+ child: _buildBody(+ context,+ userProfile,+ workspaceLatest,+ ),),),),