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: desktop Search UI revamp (#7895)

Morn014928cf19e5
diff --git a/frontend/appflowy_flutter/lib/ai/widgets/prompt_input/desktop_prompt_input.dart b/frontend/appflowy_flutter/lib/ai/widgets/prompt_input/desktop_prompt_input.dart
index 288110c5f2..938aef6f00 100644
--- a/frontend/appflowy_flutter/lib/ai/widgets/prompt_input/desktop_prompt_input.dart
+++ b/frontend/appflowy_flutter/lib/ai/widgets/prompt_input/desktop_prompt_input.dart
@@ -3,6 +3,7 @@ import 'package:appflowy/plugins/ai_chat/application/chat_input_control_cubit.da
import 'package:appflowy/plugins/ai_chat/presentation/layout_define.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/util/theme_extension.dart';
+import 'package:appflowy/workspace/application/command_palette/command_palette_bloc.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/protobuf.dart';
import 'package:appflowy_ui/appflowy_ui.dart';
import 'package:flowy_infra/file_picker/file_picker_service.dart';
@@ -74,6 +75,7 @@ class _DesktopPromptInputState extends State<DesktopPromptInput> {
WidgetsBinding.instance.addPostFrameCallback((_) {
focusNode.requestFocus();
+ checkForAskingAI();
});
}
@@ -221,6 +223,26 @@ class _DesktopPromptInputState extends State<DesktopPromptInput> {
);
}
+ void checkForAskingAI() {
+ final paletteBloc = context.read<CommandPaletteBloc?>(),
+ paletteState = paletteBloc?.state;
+ if (paletteBloc == null || paletteState == null) return;
+ final isAskingAI = paletteState.askAI;
+ if (!isAskingAI) return;
+ paletteBloc.add(CommandPaletteEvent.askedAI());
+ final query = paletteState.query ?? '';
+ if (query.isEmpty) return;
+ final sources = (paletteState.askAISources ?? []).map((e) => e.id).toList();
+ final metadata =
+ context.read<AIPromptInputBloc?>()?.consumeMetadata() ?? {};
+ final promptState = context.read<AIPromptInputBloc?>()?.state;
+ final predefinedFormat = promptState?.predefinedFormat;
+ if (sources.isNotEmpty) {
+ widget.onUpdateSelectedSources(sources);
+ }
+ widget.onSubmitted.call(query, predefinedFormat, metadata);
+ }
+
void startMentionPageFromButton() {
if (overlayController.isShowing) {
return;
diff --git a/frontend/appflowy_flutter/lib/mobile/presentation/search/mobile_search_ask_ai_entrance.dart b/frontend/appflowy_flutter/lib/mobile/presentation/search/mobile_search_ask_ai_entrance.dart
index 7a695da46c..7d07d2bd36 100644
--- a/frontend/appflowy_flutter/lib/mobile/presentation/search/mobile_search_ask_ai_entrance.dart
+++ b/frontend/appflowy_flutter/lib/mobile/presentation/search/mobile_search_ask_ai_entrance.dart
@@ -19,7 +19,7 @@ class MobileSearchAskAiEntrance extends StatelessWidget {
onTap: () {
context
.read<CommandPaletteBloc?>()
- ?.add(CommandPaletteEvent.gointToAskAI());
+ ?.add(CommandPaletteEvent.goingToAskAI());
mobileCreateNewAIChatNotifier.value =
mobileCreateNewAIChatNotifier.value + 1;
},
diff --git a/frontend/appflowy_flutter/lib/mobile/presentation/search/mobile_search_textfield.dart b/frontend/appflowy_flutter/lib/mobile/presentation/search/mobile_search_textfield.dart
index 6dc1872e07..06c1fc1e20 100644
--- a/frontend/appflowy_flutter/lib/mobile/presentation/search/mobile_search_textfield.dart
+++ b/frontend/appflowy_flutter/lib/mobile/presentation/search/mobile_search_textfield.dart
@@ -150,10 +150,9 @@ class _MobileSearchTextfieldState extends State<MobileSearchTextfield> {
child: Padding(
padding: const EdgeInsets.fromLTRB(4, 10, 8, 10),
child: FlowySvg(
- FlowySvgs.clear_s,
- blendMode: null,
- color: theme.iconColorScheme.tertiary,
- size: Size.square(20),
+ FlowySvgs.search_clear_m,
+ color: theme.iconColorScheme.secondary,
+ size: const Size.square(20),
),
),
)
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.dart
index c40f728f3f..cd116d4ec9 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,4 +1,6 @@
import 'package:appflowy/startup/startup.dart';
+import 'package:appflowy_ui/appflowy_ui.dart';
+import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
@@ -53,3 +55,44 @@ class ViewAncestorState with _$ViewAncestorState {
ancestor: ViewAncestor.empty(),
);
}
+
+extension ViewAncestorTextExtension on ViewAncestorState {
+ Widget buildPath(BuildContext context, {TextStyle? style}) {
+ final theme = AppFlowyTheme.of(context);
+ final ancestors = ancestor.ancestors;
+ final textStyle = style ??
+ theme.textStyle.caption.standard(color: theme.textColorScheme.tertiary);
+ return LayoutBuilder(
+ builder: (context, constrains) {
+ final List<String> displayPath = ancestors.map((e) => e.name).toList();
+ if (displayPath.isEmpty) return const SizedBox.shrink();
+ TextPainter textPainter =
+ _buildTextPainter(displayPath.join(' / '), textStyle);
+ textPainter.layout(maxWidth: constrains.maxWidth);
+ if (textPainter.didExceedMaxLines && displayPath.length > 2) {
+ displayPath.removeAt(displayPath.length - 2);
+ displayPath.insert(displayPath.length - 1, '...');
+ }
+ textPainter = _buildTextPainter(displayPath.join(' / '), textStyle);
+ textPainter.layout(maxWidth: constrains.maxWidth);
+ while (textPainter.didExceedMaxLines && displayPath.length > 3) {
+ displayPath.removeAt(displayPath.length - 2);
+ textPainter = _buildTextPainter(displayPath.join(' / '), textStyle);
+ textPainter.layout(maxWidth: constrains.maxWidth);
+ }
+ return Text(
+ displayPath.join(' / '),
+ style: textStyle,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ );
+ },
+ );
+ }
+
+ TextPainter _buildTextPainter(String text, TextStyle style) => TextPainter(
+ text: TextSpan(text: text, style: style),
+ maxLines: 1,
+ textDirection: TextDirection.ltr,
+ );
+}
diff --git a/frontend/appflowy_flutter/lib/plugins/database/application/cell/bloc/date_cell_editor_bloc.dart b/frontend/appflowy_flutter/lib/plugins/database/application/cell/bloc/date_cell_editor_bloc.dart
index 09860c7978..c34a6ac9e9 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/application/cell/bloc/date_cell_editor_bloc.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/application/cell/bloc/date_cell_editor_bloc.dart
@@ -219,7 +219,8 @@ class DateCellEditorBloc
} else {
if (option == ReminderOption.none) {
// remove reminder from reminder bloc and cell data
- _reminderBloc.add(ReminderEvent.removeReminder(reminderId: state.reminderId));
+ _reminderBloc
+ .add(ReminderEvent.removeReminder(reminderId: state.reminderId));
await _updateCellReminderId("");
} else {
// Update reminder
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/date_transaction_handler.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/date_transaction_handler.dart
index 30a5339bbd..c2dfd1c408 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/date_transaction_handler.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/date_transaction_handler.dart
@@ -95,7 +95,8 @@ class DateTransactionHandler extends MentionTransactionHandler {
final reminderId = data.$2[MentionBlockKeys.reminderId];
if (reminderId case String _ when reminderId.isNotEmpty) {
- getIt<ReminderBloc>().add(ReminderEvent.removeReminder(reminderId: reminderId));
+ getIt<ReminderBloc>()
+ .add(ReminderEvent.removeReminder(reminderId: reminderId));
}
}
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/mention_date_block.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/mention_date_block.dart
index e07b6c0403..dcc3af5a77 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/mention_date_block.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/mention_date_block.dart
@@ -146,9 +146,9 @@ class _MentionDateBlockState extends State<MentionDateBlock> {
} else {
final rootContext = widget.editorState.document.root.context;
if (rootContext != null && _reminderId != null) {
- rootContext
- .read<ReminderBloc?>()
- ?.add(ReminderEvent.removeReminder(reminderId: _reminderId!));
+ rootContext.read<ReminderBloc?>()?.add(
+ ReminderEvent.removeReminder(reminderId: _reminderId!),
+ );
}
_updateBlock(selectedDay, includeTime: _includeTime);
}
diff --git a/frontend/appflowy_flutter/lib/plugins/trash/src/trash_cell.dart b/frontend/appflowy_flutter/lib/plugins/trash/src/trash_cell.dart
index e1cfefeffa..548f713757 100644
--- a/frontend/appflowy_flutter/lib/plugins/trash/src/trash_cell.dart
+++ b/frontend/appflowy_flutter/lib/plugins/trash/src/trash_cell.dart
@@ -1,10 +1,11 @@
import 'package:appflowy/generated/flowy_svgs.g.dart';
+import 'package:appflowy/generated/locale_keys.g.dart';
+import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/style_widget/icon_button.dart';
import 'package:flowy_infra_ui/style_widget/text.dart';
import 'package:flowy_infra_ui/widget/spacing.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/trash.pb.dart';
import 'package:flutter/material.dart';
-import 'package:intl/intl.dart';
import 'package:fixnum/fixnum.dart' as $fixnum;
import 'sizes.dart';
@@ -27,7 +28,11 @@ class TrashCell extends StatelessWidget {
children: [
SizedBox(
width: TrashSizes.fileNameWidth,
- child: FlowyText(object.name),
+ child: FlowyText(
+ object.name.isEmpty
+ ? LocaleKeys.menuAppHeader_defaultNewPageName.tr()
+ : object.name,
+ ),
),
SizedBox(
width: TrashSizes.lashModifyWidth,
diff --git a/frontend/appflowy_flutter/lib/startup/tasks/app_widget.dart b/frontend/appflowy_flutter/lib/startup/tasks/app_widget.dart
index 9c066abff1..bb1386ee15 100644
--- a/frontend/appflowy_flutter/lib/startup/tasks/app_widget.dart
+++ b/frontend/appflowy_flutter/lib/startup/tasks/app_widget.dart
@@ -138,7 +138,7 @@ class ApplicationWidget extends StatefulWidget {
class _ApplicationWidgetState extends State<ApplicationWidget> {
late final GoRouter routerConfig;
- final _commandPaletteNotifier = ValueNotifier<bool>(false);
+ final _commandPaletteNotifier = ValueNotifier(CommandPaletteNotifierValue());
final themeBuilder = AppFlowyDefaultTheme();
diff --git a/frontend/appflowy_flutter/lib/workspace/application/command_palette/command_palette_bloc.dart b/frontend/appflowy_flutter/lib/workspace/application/command_palette/command_palette_bloc.dart
index 116598d63f..b0ca181f85 100644
--- a/frontend/appflowy_flutter/lib/workspace/application/command_palette/command_palette_bloc.dart
+++ b/frontend/appflowy_flutter/lib/workspace/application/command_palette/command_palette_bloc.dart
@@ -286,14 +286,14 @@ class CommandPaletteBloc
_GoingToAskAI event,
Emitter<CommandPaletteState> emit,
) {
- emit(state.copyWith(askAI: true));
+ emit(state.copyWith(askAI: true, askAISources: event.sources));
}
FutureOr<void> _onAskedAI(
_AskedAI event,
Emitter<CommandPaletteState> emit,
) {
- emit(state.copyWith(askAI: false));
+ emit(state.copyWith(askAI: false, askAISources: null));
}
bool _isActiveSearch(String searchId) =>
@@ -325,7 +325,9 @@ class CommandPaletteEvent with _$CommandPaletteEvent {
@Default(null) String? workspaceId,
}) = _WorkspaceChanged;
const factory CommandPaletteEvent.clearSearch() = _ClearSearch;
- const factory CommandPaletteEvent.gointToAskAI() = _GoingToAskAI;
+ const factory CommandPaletteEvent.goingToAskAI({
+ @Default(null) List<SearchSourcePB>? sources,
+ }) = _GoingToAskAI;
const factory CommandPaletteEvent.askedAI() = _AskedAI;
}
@@ -358,6 +360,7 @@ class CommandPaletteState with _$CommandPaletteState {
required bool searching,
required bool generatingAIOverview,
@Default(false) bool askAI,
+ @Default(null) List<SearchSourcePB>? askAISources,
@Default([]) List<TrashPB> trash,
@Default(null) String? searchId,
}) = _CommandPaletteState;
diff --git a/frontend/appflowy_flutter/lib/workspace/application/command_palette/search_result_ext.dart b/frontend/appflowy_flutter/lib/workspace/application/command_palette/search_result_ext.dart
index 0b386cded3..abce585681 100644
--- a/frontend/appflowy_flutter/lib/workspace/application/command_palette/search_result_ext.dart
+++ b/frontend/appflowy_flutter/lib/workspace/application/command_palette/search_result_ext.dart
@@ -19,7 +19,8 @@ extension GetIcon on ResultIconPB {
lineHeight: lineHeight,
)
: null;
- } else if (ty == ResultIconTypePB.Icon) {
+ } else if (iconType == ResultIconTypePB.Icon ||
+ iconType == ResultIconTypePB.Url) {
if (_resultIconValueTypes.contains(iconValue)) {
return FlowySvg(
getViewSvg(),
diff --git a/frontend/appflowy_flutter/lib/workspace/application/recent/recent_views_bloc.dart b/frontend/appflowy_flutter/lib/workspace/application/recent/recent_views_bloc.dart
index d67c24e854..d8797f0e3f 100644
--- a/frontend/appflowy_flutter/lib/workspace/application/recent/recent_views_bloc.dart
+++ b/frontend/appflowy_flutter/lib/workspace/application/recent/recent_views_bloc.dart
@@ -46,6 +46,11 @@ class RecentViewsBloc extends Bloc<RecentViewsEvent, RecentViewsState> {
await _service.reset();
add(const RecentViewsEvent.fetchRecentViews());
},
+ hoverView: (e) async {
+ emit(
+ state.copyWith(hoveredView: e.view),
+ );
+ },
);
},
);
@@ -64,6 +69,7 @@ class RecentViewsEvent with _$RecentViewsEvent {
RemoveRecentViews;
const factory RecentViewsEvent.fetchRecentViews() = FetchRecentViews;
const factory RecentViewsEvent.resetRecentViews() = ResetRecentViews;
+ const factory RecentViewsEvent.hoverView(ViewPB view) = HoverView;
}
@freezed
@@ -71,6 +77,7 @@ class RecentViewsState with _$RecentViewsState {
const factory RecentViewsState({
required List<SectionViewPB> views,
@Default(true) bool isLoading,
+ @Default(null) ViewPB? hoveredView,
}) = _RecentViewsState;
factory RecentViewsState.initial() => const RecentViewsState(views: []);
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.dart
index 648712bd15..1d627ef173 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
@@ -1,15 +1,28 @@
+import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
+import 'package:appflowy/startup/plugin/plugin.dart';
+import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/workspace/application/command_palette/command_palette_bloc.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/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:appflowy/workspace/presentation/home/menu/menu_shared_state.dart';
+import 'package:appflowy_backend/protobuf/flowy-folder/view.pbenum.dart';
+import 'package:appflowy_backend/protobuf/flowy-user/workspace.pbenum.dart';
+import 'package:appflowy_ui/appflowy_ui.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
+import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:universal_platform/universal_platform.dart';
+import 'widgets/search_ask_ai_entrance.dart';
+
class CommandPalette extends InheritedWidget {
CommandPalette({
super.key,
@@ -19,7 +32,7 @@ class CommandPalette extends InheritedWidget {
child: _CommandPaletteController(notifier: notifier, child: child),
);
- final ValueNotifier<bool> notifier;
+ final ValueNotifier<CommandPaletteNotifierValue> notifier;
static CommandPalette of(BuildContext context) {
final CommandPalette? result =
@@ -30,7 +43,17 @@ class CommandPalette extends InheritedWidget {
return result!;
}
- void toggle() => notifier.value = !notifier.value;
+ void toggle({
+ UserWorkspaceBloc? workspaceBloc,
+ SpaceBloc? spaceBloc,
+ }) {
+ final value = notifier.value;
+ notifier.value = notifier.value.copyWith(
+ isOpen: !value.isOpen,
+ userWorkspaceBloc: workspaceBloc,
+ spaceBloc: spaceBloc,
+ );
+ }
@override
bool updateShouldNotify(covariant InheritedWidget oldWidget) => false;
@@ -47,7 +70,7 @@ class _CommandPaletteController extends StatefulWidget {
});
final Widget? child;
- final ValueNotifier<bool> notifier;
+ final ValueNotifier<CommandPaletteNotifierValue> notifier;
@override
State<_CommandPaletteController> createState() =>
@@ -55,7 +78,8 @@ class _CommandPaletteController extends StatefulWidget {
}
class _CommandPaletteControllerState extends State<_CommandPaletteController> {
- late ValueNotifier<bool> _toggleNotifier = widget.notifier;
+ late ValueNotifier<CommandPaletteNotifierValue> _toggleNotifier =
+ widget.notifier;
bool _isOpen = false;
@override
@@ -81,19 +105,25 @@ class _CommandPaletteControllerState extends State<_CommandPaletteController> {
}
void _onToggle() {
- if (_toggleNotifier.value && !_isOpen) {
+ if (_toggleNotifier.value.isOpen && !_isOpen) {
_isOpen = true;
+ final workspaceBloc = _toggleNotifier.value.userWorkspaceBloc;
+ final spaceBloc = _toggleNotifier.value.spaceBloc;
FlowyOverlay.show(
context: context,
- builder: (_) => BlocProvider.value(
- value: context.read<CommandPaletteBloc>(),
+ builder: (_) => MultiBlocProvider(
+ providers: [
+ BlocProvider.value(value: context.read<CommandPaletteBloc>()),
+ if (workspaceBloc != null) BlocProvider.value(value: workspaceBloc),
+ if (spaceBloc != null) BlocProvider.value(value: spaceBloc),
+ ],
child: CommandPaletteModal(shortcutBuilder: _buildShortcut),
),
).then((_) {
_isOpen = false;
- _toggleNotifier.value = false;
+ _toggleNotifier.value = _toggleNotifier.value.copyWith(isOpen: false);
});
- } else if (!_toggleNotifier.value && _isOpen) {
+ } else if (!_toggleNotifier.value.isOpen && _isOpen) {
FlowyOverlay.pop(context);
_isOpen = false;
}
@@ -107,8 +137,8 @@ class _CommandPaletteControllerState extends State<_CommandPaletteController> {
actions: {
_ToggleCommandPaletteIntent:
CallbackAction<_ToggleCommandPaletteIntent>(
- onInvoke: (intent) =>
- _toggleNotifier.value = !_toggleNotifier.value,
+ onInvoke: (intent) => _toggleNotifier.value = _toggleNotifier.value
+ .copyWith(isOpen: !_toggleNotifier.value.isOpen),
),
},
shortcuts: {
@@ -130,68 +160,155 @@ class CommandPaletteModal extends StatelessWidget {
@override
Widget build(BuildContext context) {
- return BlocBuilder<CommandPaletteBloc, CommandPaletteState>(
- builder: (context, state) => FlowyDialog(
- alignment: Alignment.topCenter,
- insetPadding: const EdgeInsets.only(top: 100),
- constraints: const BoxConstraints(
- maxHeight: 600,
- maxWidth: 800,
- minHeight: 600,
- ),
- expandHeight: false,
- child: shortcutBuilder(
- // Change mainAxisSize to max so Expanded works correctly.
- Column(
- children: [
- SearchField(query: state.query, isLoading: state.searching),
- if (state.query?.isEmpty ?? true) ...[
- const Divider(height: 0),
- Flexible(
- child: RecentViewsList(
- onSelected: () => FlowyOverlay.pop(context),
- ),
- ),
- ],
- if (state.combinedResponseItems.isNotEmpty &&
- (state.query?.isNotEmpty ?? false)) ...[
- const Divider(height: 0),
- Flexible(
- child: SearchResultList(
- trash: state.trash,
- resultItems: state.combinedResponseItems.values.toList(),
- resultSummaries: state.resultSummaries,
- ),
- ),
- ]
- // When there are no results and the query is not empty and not loading,
- // show the no results message, centered in the available space.
- else if ((state.query?.isNotEmpty ?? false) &&
- !state.searching) ...[
- const Divider(height: 0),
- Expanded(
- child: const _NoResultsHint(),
- ),
- ],
- ],
- ),
- ),
+ final workspaceState = context.read<UserWorkspaceBloc?>()?.state;
+ final showAskingAI =
+ workspaceState?.userProfile.workspaceType == WorkspaceTypePB.ServerW;
+ return BlocListener<CommandPaletteBloc, CommandPaletteState>(
+ listener: (_, state) {
+ if (state.askAI && context.mounted) {
+ if (Navigator.canPop(context)) FlowyOverlay.pop(context);
+ final currentWorkspace = workspaceState?.workspaces;
+ final spaceBloc = context.read<SpaceBloc?>();
+ if (currentWorkspace != null && spaceBloc != null) {
+ spaceBloc.add(
+ SpaceEvent.createPage(
+ name: '',
+ layout: ViewLayoutPB.Chat,
+ index: 0,
+ openAfterCreate: true,
+ ),
+ );
+ }
+ }
+ },
+ child: BlocBuilder<CommandPaletteBloc, CommandPaletteState>(
+ builder: (context, state) {
+ final noQuery = state.query?.isEmpty ?? true, hasQuery = !noQuery;
+ final hasResult = state.combinedResponseItems.isNotEmpty;
+ return FlowyDialog(
+ alignment: Alignment.topCenter,
+ insetPadding: const EdgeInsets.only(top: 100),
+ constraints: const BoxConstraints(
+ maxHeight: 640,
+ maxWidth: 900,
+ minHeight: 640,
+ ),
+ expandHeight: false,
+ child: shortcutBuilder(
+ // Change mainAxisSize to max so Expanded works correctly.
+ Column(
+ children: [
+ SearchField(query: state.query, isLoading: state.searching),
+ if (noQuery)
+ Flexible(
+ child: RecentViewsList(
+ onSelected: () => FlowyOverlay.pop(context),
+ ),
+ ),
+ if (hasResult && hasQuery) ...[
+ AFDivider(),
+ Flexible(
+ child: SearchResultList(
+ trash: state.trash,
+ resultItems:
+ state.combinedResponseItems.values.toList(),
+ resultSummaries: state.resultSummaries,
+ ),
+ ),
+ ]
+ // When there are no results and the query is not empty and not loading,
+ // show the no results message, centered in the available space.
+ else if (hasQuery && !state.searching) ...[
+ AFDivider(),
+ if (showAskingAI) SearchAskAiEntrance(),
+ Expanded(
+ child: const NoSearchResultsHint(),
+ ),
+ ],
+ ],
+ ),
+ ),
+ );
+ },
),
);
}
}
/// Updated _NoResultsHint now centers its content.
-class _NoResultsHint extends StatelessWidget {
- const _NoResultsHint();
+class NoSearchResultsHint extends StatelessWidget {
+ const NoSearchResultsHint({super.key});
@override
Widget build(BuildContext context) {
+ final theme = AppFlowyTheme.of(context),
+ textColor = theme.textColorScheme.secondary;
return Center(
- child: FlowyText.regular(
- LocaleKeys.commandPalette_noResultsHint.tr(),
- textAlign: TextAlign.center,
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ FlowySvg(
+ FlowySvgs.m_home_search_icon_m,
+ color: theme.iconColorScheme.secondary,
+ size: Size.square(24),
+ ),
+ const VSpace(8),
+ Text(
+ LocaleKeys.search_noResultForSearching.tr(),
+ style: theme.textStyle.body.enhanced(color: textColor),
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ ),
+ const VSpace(4),
+ RichText(
+ textAlign: TextAlign.center,
+ text: TextSpan(
+ text: LocaleKeys.search_noResultForSearchingHintWithoutTrash.tr(),
+ style: theme.textStyle.caption.standard(color: textColor),
+ children: [
+ TextSpan(
+ text: LocaleKeys.trash_text.tr(),
+ style: theme.textStyle.caption.underline(color: textColor),
+ recognizer: TapGestureRecognizer()
+ ..onTap = () {
+ FlowyOverlay.pop(context);
+ getIt<MenuSharedState>().latestOpenView = null;
+ getIt<TabsBloc>().add(
+ TabsEvent.openPlugin(
+ plugin: makePlugin(pluginType: PluginType.trash),
+ ),
+ );
+ },
+ ),
+ ],
+ ),
+ ),
+ ],
),
);
}
}
+
+class CommandPaletteNotifierValue {
+ CommandPaletteNotifierValue({
+ this.isOpen = false,
+ this.userWorkspaceBloc,
+ this.spaceBloc,
+ });
+
+ final bool isOpen;
+ final UserWorkspaceBloc? userWorkspaceBloc;
+ final SpaceBloc? spaceBloc;
+
+ CommandPaletteNotifierValue copyWith({
+ bool? isOpen,
+ UserWorkspaceBloc? userWorkspaceBloc,
+ SpaceBloc? spaceBloc,
+ }) {
+ return CommandPaletteNotifierValue(
+ isOpen: isOpen ?? this.isOpen,
+ userWorkspaceBloc: userWorkspaceBloc ?? this.userWorkspaceBloc,
+ spaceBloc: spaceBloc ?? this.spaceBloc,
+ );
+ }
+}
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.dart
new file mode 100644
index 0000000000..e85482385b
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/page_preview.dart
@@ -0,0 +1,160 @@
+import 'package:appflowy/generated/flowy_svgs.g.dart';
+import 'package:appflowy/generated/locale_keys.g.dart';
+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';
+import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
+import 'package:appflowy_ui/appflowy_ui.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';
+
+class PagePreview extends StatelessWidget {
+ const PagePreview({super.key, required this.view});
+ final ViewPB view;
+
+ @override
+ Widget build(BuildContext context) {
+ final theme = AppFlowyTheme.of(context);
+
+ return Padding(
+ padding: const EdgeInsets.symmetric(
+ horizontal: 20,
+ vertical: 24,
+ ),
+ child: SingleChildScrollView(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ SizedBox.square(
+ dimension: 24,
+ child: Center(child: buildIcon(theme, view)),
+ ),
+ VSpace(8),
+ buildTitle(context, view),
+ buildPath(context, view),
+ ...buildTime(
+ context,
+ LocaleKeys.commandPalette_created.tr(),
+ view.createTime.toDateTime(),
+ ),
+ if (view.lastEdited != view.createTime)
+ ...buildTime(
+ context,
+ LocaleKeys.commandPalette_edited.tr(),
+ view.lastEdited.toDateTime(),
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+
+ Widget buildIcon(AppFlowyThemeData theme, ViewPB view) {
+ return view.icon.value.isNotEmpty
+ ? RawEmojiIconWidget(
+ emoji: view.icon.toEmojiIconData(),
+ emojiSize: 20.0,
+ lineHeight: 1,
+ )
+ : FlowySvg(
+ view.iconData,
+ size: const Size.square(20),
+ color: theme.iconColorScheme.secondary,
+ );
+ }
+
+ Widget buildTitle(BuildContext context, ViewPB view) {
+ final theme = AppFlowyTheme.of(context);
+ 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,
+ ),
+ ),
+ ),
+ HSpace(4),
+ FlowyTooltip(
+ message: LocaleKeys.settings_files_open.tr(),
+ child: AFGhostButton.normal(
+ size: AFButtonSize.s,
+ padding: EdgeInsets.all(theme.spacing.xs),
+ onTap: () {
+ context.read<SearchResultListBloc?>()?.add(
+ SearchResultListEvent.openPage(pageId: view.id),
+ );
+ },
+ builder: (context, isHovering, disabled) => FlowySvg(
+ FlowySvgs.search_arrow_right_m,
+ size: const Size.square(20),
+ ),
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+
+ Widget buildPath(BuildContext context, ViewPB view) {
+ final theme = AppFlowyTheme.of(context);
+ return BlocProvider(
+ key: ValueKey(view.id),
+ create: (context) => ViewAncestorBloc(view.id),
+ child: BlocBuilder<ViewAncestorBloc, ViewAncestorState>(
+ builder: (context, state) {
+ if (state.ancestor.ancestors.isEmpty) return const SizedBox.shrink();
+ return Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ VSpace(16),
+ Text(
+ LocaleKeys.commandPalette_location.tr(),
+ style: theme.textStyle.caption
+ .standard(color: theme.textColorScheme.primary),
+ ),
+ state.buildPath(
+ context,
+ style: theme.textStyle.caption.standard(
+ color: theme.textColorScheme.secondary,
+ ),
+ ),
+ ],
+ );
+ },
+ ),
+ );
+ }
+
+ List<Widget> buildTime(BuildContext context, String title, DateTime time) {
+ final theme = AppFlowyTheme.of(context);
+ final appearanceSettings = context.watch<AppearanceSettingsCubit>().state;
+ final dateFormat = appearanceSettings.dateFormat,
+ timeFormat = appearanceSettings.timeFormat;
+ return [
+ VSpace(12),
+ Text(
+ title,
+ style: theme.textStyle.caption
+ .standard(color: theme.textColorScheme.primary),
+ ),
+ Text(
+ dateFormat.formatDate(time, true, timeFormat),
+ style: theme.textStyle.caption
+ .standard(color: theme.textColorScheme.secondary),
+ ),
+ ];
+ }
+}
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.dart
index 3bc160ee81..ba5184a6b1 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
@@ -3,14 +3,20 @@ 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/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';
import 'package:appflowy/workspace/presentation/command_palette/widgets/search_recent_view_cell.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
+import 'package:appflowy_backend/protobuf/flowy-user/workspace.pbenum.dart';
+import 'package:appflowy_ui/appflowy_ui.dart';
import 'package:easy_localization/easy_localization.dart';
-import 'package:flowy_infra_ui/style_widget/text.dart';
+import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
+import 'page_preview.dart';
+import 'search_ask_ai_entrance.dart';
+
class RecentViewsList extends StatelessWidget {
const RecentViewsList({super.key, required this.onSelected});
@@ -26,39 +32,104 @@ class RecentViewsList extends StatelessWidget {
// We remove duplicates by converting the list to a set first
final List<ViewPB> recentViews =
state.views.map((e) => e.item).toSet().toList();
+ final theme = AppFlowyTheme.of(context);
+ final workspaceState = context.read<UserWorkspaceBloc?>()?.state;
+ final showAskingAI = workspaceState?.userProfile.workspaceType ==
+ WorkspaceTypePB.ServerW;
+ final hoveredView = state.hoveredView;
+ return Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ AFDivider(),
+ Flexible(
+ child: Row(
+ children: [
+ Flexible(
+ flex: 2,
+ child: ScrollControllerBuilder(
+ builder: (context, controller) {
+ return FlowyScrollbar(
+ controller: controller,
+ child: SingleChildScrollView(
+ controller: controller,
+ physics: const ClampingScrollPhysics(),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ if (showAskingAI) SearchAskAiEntrance(),
+ Container(
+ height: 20,
+ padding: const EdgeInsets.symmetric(
+ horizontal: 8,
+ ),
+ margin: const EdgeInsets.symmetric(
+ horizontal: 12,
+ vertical: 8,
+ ),
+ child: Text(
+ LocaleKeys.sideBar_recent.tr(),
+ style: theme.textStyle.body.enhanced(
+ color: theme.textColorScheme.secondary,
+ ),
+ ),
+ ),
+ ListView.separated(
+ shrinkWrap: true,
+ physics:
+ const NeverScrollableScrollPhysics(),
+ itemCount: recentViews.length,
+ padding:
+ EdgeInsets.symmetric(horizontal: 12),
+ itemBuilder: (_, index) {
+ final view = recentViews[index];
- return ListView.separated(
- shrinkWrap: true,
- physics: const ClampingScrollPhysics(),
- itemCount: recentViews.length + 1,
- itemBuilder: (_, index) {
- if (index == 0) {
- return Padding(
- padding: const EdgeInsets.symmetric(
- horizontal: 16,
- vertical: 8,
- ),
- child: FlowyText(
- LocaleKeys.commandPalette_recentHistory.tr(),
- ),
- );
- }
-
- final view = recentViews[index - 1];
- final icon = view.icon.value.isNotEmpty
- ? EmojiIconWidget(
- emoji: view.icon.toEmojiIconData(),
- emojiSize: 18.0,
- )
- : FlowySvg(view.iconData, size: const Size.square(20));
+ final icon = view.icon.value.isNotEmpty
+ ? RawEmojiIconWidget(
+ emoji:
+ view.icon.toEmojiIconData(),
+ emojiSize: 16.0,
+ lineHeight: 20 / 16,
+ )
+ : FlowySvg(
+ view.iconData,
+ size: const Size.square(20),
+ color: theme
+ .iconColorScheme.secondary,
+ );
- return SearchRecentViewCell(
- icon: SizedBox(width: 24, child: icon),
- view: view,
- onSelected: onSelected,
- );
- },
- separatorBuilder: (_, __) => const Divider(height: 0),
+ return SearchRecentViewCell(
+ icon: SizedBox.square(
+ dimension: 24,
+ child: Center(child: icon),
+ ),
+ view: view,
+ onSelected: onSelected,
+ );
+ },
+ separatorBuilder: (_, __) => AFDivider(),
+ ),
+ VSpace(8),
+ ],
+ ),
+ ),
+ );
+ },
+ ),
+ ),
+ if (hoveredView != null) ...[
+ AFDivider(axis: Axis.vertical),
+ Flexible(
+ child: Align(
+ alignment: Alignment.topLeft,
+ child: PagePreview(view: hoveredView),
+ ),
+ ),
+ ],
+ ],
+ ),
+ ),
+ ],
);
},
),
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/search_ask_ai_entrance.dart b/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/search_ask_ai_entrance.dart
new file mode 100644
index 0000000000..8e26abcf28
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/search_ask_ai_entrance.dart
@@ -0,0 +1,227 @@
+import 'package:appflowy/generated/flowy_svgs.g.dart';
+import 'package:appflowy/generated/locale_keys.g.dart';
+import 'package:appflowy/workspace/application/command_palette/command_palette_bloc.dart';
+import 'package:appflowy_backend/protobuf/flowy-search/result.pb.dart';
+import 'package:appflowy_ui/appflowy_ui.dart';
+import 'package:easy_localization/easy_localization.dart';
+import 'package:flowy_infra_ui/widget/spacing.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter_bloc/flutter_bloc.dart';
+
+import 'search_summary_cell.dart';
+
+class SearchAskAiEntrance extends StatelessWidget {
+ const SearchAskAiEntrance({super.key});
+
+ @override
+ Widget build(BuildContext context) {
+ final bloc = context.read<CommandPaletteBloc?>(), state = bloc?.state;
+ final generatingAIOverview = state?.generatingAIOverview ?? false;
+ final hasAIOverview =
+ _mockSummary?.isNotEmpty ?? state?.resultSummaries.isNotEmpty ?? false;
+ if (generatingAIOverview) {
+ return _AISearching();
+ } else if (hasAIOverview) {
+ return _AIOverview();
+ }
+ return _AskAIFor();
+ }
+}
+
+class _AskAIFor extends StatelessWidget {
+ const _AskAIFor();
+
+ @override
+ Widget build(BuildContext context) {
+ final theme = AppFlowyTheme.of(context);
+ final sapceM = theme.spacing.m, spaceL = theme.spacing.l;
+ return Padding(
+ padding: EdgeInsets.fromLTRB(spaceL, sapceM, spaceL, 0),
+ child: AFBaseButton(
+ borderRadius: sapceM,
+ padding: EdgeInsets.symmetric(vertical: spaceL, horizontal: sapceM),
+ backgroundColor: (context, isHovering, disable) {
+ if (isHovering) {
+ return Theme.of(context).colorScheme.secondary;
+ }
+ return theme.fillColorScheme.transparent;
+ },
+ borderColor: (context, isHovering, disable, isFocused) =>
+ theme.fillColorScheme.transparent,
+ builder: (ctx, isHovering, disable) {
+ return Row(
+ children: [
+ FlowySvg(
+ FlowySvgs.m_home_ai_chat_icon_m,
+ size: Size.square(20),
+ blendMode: null,
+ ),
+ HSpace(12),
+ buildText(context),
+ ],
+ );
+ },
+ onTap: () {
+ context
+ .read<CommandPaletteBloc?>()
+ ?.add(CommandPaletteEvent.goingToAskAI());
+ },
+ ),
+ );
+ }
+
+ Widget buildText(BuildContext context) {
+ final theme = AppFlowyTheme.of(context);
+ final bloc = context.read<CommandPaletteBloc?>();
+ final queryText = bloc?.state.query ?? '';
+ if (queryText.isEmpty) {
+ return Text(
+ LocaleKeys.search_askAIAnything.tr(),
+ style:
+ theme.textStyle.body.standard(color: theme.textColorScheme.primary),
+ );
+ }
+ return Flexible(
+ child: RichText(
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ text: TextSpan(
+ children: [
+ TextSpan(
+ text: LocaleKeys.search_askAIFor.tr(),
+ style: theme.textStyle.body
+ .standard(color: theme.textColorScheme.primary),
+ ),
+ TextSpan(
+ text: ' "$queryText"',
+ style: theme.textStyle.body
+ .enhanced(color: theme.textColorScheme.primary),
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+}
+
+class _AISearching extends StatelessWidget {
+ const _AISearching();
+
+ @override
+ Widget build(BuildContext context) {
+ final theme = AppFlowyTheme.of(context);
+ return Padding(
+ padding: EdgeInsets.fromLTRB(16, 20, 16, 8),
+ child: SizedBox(
+ height: 22,
+ child: Row(
+ children: [
+ FlowySvg(
+ FlowySvgs.ai_searching_icon_m,
+ size: Size.square(20),
+ blendMode: null,
+ ),
+ HSpace(8),
+ Text(
+ LocaleKeys.search_searching.tr(),
+ style: theme.textStyle.heading4
+ .enhanced(color: theme.textColorScheme.secondary),
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+}
+
+class _AIOverview extends StatelessWidget {
+ const _AIOverview();
+
+ @override
+ Widget build(BuildContext context) {
+ final bloc = context.read<CommandPaletteBloc?>(), state = bloc?.state;
+ final theme = AppFlowyTheme.of(context);
+ final summaries = _mockSummary ?? state?.resultSummaries ?? [];
+ if (summaries.isEmpty) {
+ return const SizedBox.shrink();
+ }
+ return Padding(
+ padding: EdgeInsets.fromLTRB(16, 20, 16, 8),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ buildHeader(context),
+ VSpace(8),
+ LayoutBuilder(
+ builder: (context, constrains) {
+ final summary = summaries.first;
+ return SearchSummaryCell(
+ key: ValueKey(summary.content.trim()),
+ summary: summary,
+ maxWidth: constrains.maxWidth,
+ theme: AppFlowyTheme.of(context),
+ );
+ },
+ ),
+ VSpace(8),
+ SizedBox(
+ width: 143,
+ child: AFOutlinedButton.normal(
+ padding: EdgeInsets.symmetric(horizontal: 12, vertical: 6),
+ borderRadius: 16,
+ builder: (context, hovering, disabled) {
+ return Row(
+ children: [
+ FlowySvg(
+ FlowySvgs.chat_ai_page_s,
+ size: Size.square(20),
+ color: theme.iconColorScheme.primary,
+ ),
+ HSpace(8),
+ Text(
+ LocaleKeys.commandPalette_aiAskFollowUp.tr(),
+ style: theme.textStyle.body.standard(
+ color: theme.textColorScheme.primary,
+ ),
+ ),
+ ],
+ );
+ },
+ onTap: () {
+ context.read<CommandPaletteBloc?>()?.add(
+ CommandPaletteEvent.goingToAskAI(
+ sources: summaries.first.sources,
+ ),
+ );
+ },
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+
+ Widget buildHeader(BuildContext context) {
+ final theme = AppFlowyTheme.of(context);
+ return SizedBox(
+ height: 22,
+ child: Row(
+ children: [
+ FlowySvg(
+ FlowySvgs.ai_searching_icon_m,
+ size: Size.square(20),
+ blendMode: null,
+ ),
+ HSpace(8),
+ Text(
+ LocaleKeys.commandPalette_aiOverview.tr(),
+ style: theme.textStyle.heading4
+ .enhanced(color: theme.textColorScheme.primary),
+ ),
+ ],
+ ),
+ );
+ }
+}
+
+List<SearchSummaryPB>? _mockSummary;
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/search_field.dart b/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/search_field.dart
index 1586ab0a7e..91824c618a 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/search_field.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/search_field.dart
@@ -1,3 +1,4 @@
+import 'package:appflowy_ui/appflowy_ui.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
@@ -6,7 +7,6 @@ import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/workspace/application/command_palette/command_palette_bloc.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra/size.dart';
-import 'package:flowy_infra/theme_extension.dart';
import 'package:flowy_infra_ui/style_widget/text_field.dart';
import 'package:flowy_infra_ui/widget/flowy_tooltip.dart';
import 'package:flowy_infra_ui/widget/spacing.dart';
@@ -63,32 +63,26 @@ class _SearchFieldState extends State<SearchField> {
valueListenable: controller,
builder: (context, value, _) {
final hasText = value.text.trim().isNotEmpty;
- final clearIcon = Container(
- padding: const EdgeInsets.all(1),
- decoration: BoxDecoration(
- shape: BoxShape.circle,
- color: AFThemeExtension.of(context).lightGreyHover,
- ),
- child: const FlowySvg(
- FlowySvgs.close_s,
- size: Size.square(16),
- ),
- );
- return AnimatedOpacity(
- opacity: hasText ? 1.0 : 0.0,
- duration: const Duration(milliseconds: 200),
- child: hasText
- ? FlowyTooltip(
- message: LocaleKeys.commandPalette_clearSearchTooltip.tr(),
- child: MouseRegion(
- cursor: SystemMouseCursors.click,
- child: GestureDetector(
- onTap: _clearSearch,
- child: clearIcon,
- ),
+ if (!hasText) return const SizedBox.shrink();
+ return FlowyTooltip(
+ message: LocaleKeys.commandPalette_clearSearchTooltip.tr(),
+ child: MouseRegion(
+ cursor: SystemMouseCursors.click,
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: _clearSearch,
+ child: SizedBox.square(
+ dimension: 28,
+ child: Center(
+ child: FlowySvg(
+ FlowySvgs.search_clear_m,
+ color: AppFlowyTheme.of(context).iconColorScheme.secondary,
+ size: const Size.square(20),
),
- )
- : clearIcon,
+ ),
+ ),
+ ),
+ ),
);
},
);
@@ -96,80 +90,53 @@ class _SearchFieldState extends State<SearchField> {
@override
Widget build(BuildContext context) {
- // Cache theme and text styles
- final theme = Theme.of(context);
- final textStyle = theme.textTheme.bodySmall?.copyWith(fontSize: 14);
- final hintStyle = theme.textTheme.bodySmall?.copyWith(
- fontSize: 14,
- color: theme.hintColor,
- );
-
- // Choose the leading icon based on loading state
- final Widget leadingIcon = widget.isLoading
- ? FlowyTooltip(
- message: LocaleKeys.commandPalette_loadingTooltip.tr(),
- child: const SizedBox(
- width: 20,
- height: 20,
- child: Padding(
- padding: EdgeInsets.all(3.0),
- child: CircularProgressIndicator(strokeWidth: 2.0),
- ),
- ),
- )
- : SizedBox(
- width: 20,
- height: 20,
- child: FlowySvg(
- FlowySvgs.search_m,
- color: theme.hintColor,
- ),
- );
+ final theme = AppFlowyTheme.of(context);
- return Row(
- children: [
- const HSpace(12),
- leadingIcon,
- Expanded(
- child: FlowyTextField(
- focusNode: focusNode,
- controller: controller,
- textStyle: textStyle,
- decoration: InputDecoration(
- constraints: const BoxConstraints(maxHeight: 48),
- contentPadding: const EdgeInsets.symmetric(horizontal: 12),
- enabledBorder: const OutlineInputBorder(
- borderSide: BorderSide(color: Colors.transparent),
- borderRadius: Corners.s8Border,
- ),
- isDense: false,
- hintText: LocaleKeys.commandPalette_placeholder.tr(),
- hintStyle: hintStyle,
- errorStyle: theme.textTheme.bodySmall!
- .copyWith(color: theme.colorScheme.error),
- suffix: Row(
- mainAxisSize: MainAxisSize.min,
- children: [
- _buildSuffixIcon(context),
- const HSpace(8),
- ],
- ),
- counterText: "",
- focusedBorder: const OutlineInputBorder(
- borderRadius: Corners.s8Border,
- borderSide: BorderSide(color: Colors.transparent),
- ),
- errorBorder: OutlineInputBorder(
- borderRadius: Corners.s8Border,
- borderSide: BorderSide(color: theme.colorScheme.error),
+ return Container(
+ height: 52,
+ padding: EdgeInsets.symmetric(horizontal: 16),
+ child: Row(
+ children: [
+ FlowySvg(
+ FlowySvgs.search_icon_m,
+ color: theme.iconColorScheme.secondary,
+ size: Size.square(20),
+ ),
+ HSpace(8),
+ Expanded(
+ child: Padding(
+ padding: const EdgeInsets.symmetric(vertical: 15),
+ child: FlowyTextField(
+ focusNode: focusNode,
+ controller: controller,
+ textStyle: theme.textStyle.heading4
+ .standard(color: theme.textColorScheme.primary),
+ decoration: InputDecoration(
+ constraints: const BoxConstraints(maxHeight: 48),
+ contentPadding: EdgeInsets.zero,
+ enabledBorder: const OutlineInputBorder(
+ borderSide: BorderSide(color: Colors.transparent),
+ borderRadius: Corners.s8Border,
+ ),
+ isDense: false,
+ hintText: LocaleKeys.search_searchOrAskAI.tr(),
+ hintStyle: theme.textStyle.heading4
+ .standard(color: theme.textColorScheme.tertiary),
+ counterText: "",
+ focusedBorder: const OutlineInputBorder(
+ borderRadius: Corners.s8Border,
+ borderSide: BorderSide(color: Colors.transparent),
+ ),
+ ),
+ onChanged: (value) => context
+ .read<CommandPaletteBloc>()
+ .add(CommandPaletteEvent.searchChanged(search: value)),
),
),
- onChanged: (value) => context
- .read<CommandPaletteBloc>()
- .add(CommandPaletteEvent.searchChanged(search: value)),
),
- ),
- ],
+ _buildSuffixIcon(context),
+ ],
+ ),
);
}
@@ -178,5 +145,6 @@ class _SearchFieldState extends State<SearchField> {
context
.read<CommandPaletteBloc>()
.add(const CommandPaletteEvent.clearSearch());
+ focusNode.requestFocus();
}
}
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/search_recent_view_cell.dart b/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/search_recent_view_cell.dart
index a803f9b44c..f0cd404348 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/search_recent_view_cell.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/search_recent_view_cell.dart
@@ -1,13 +1,19 @@
+import 'package:appflowy/mobile/presentation/search/mobile_view_ancestors.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/view/view_ext.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
-import 'package:flowy_infra_ui/style_widget/text.dart';
-import 'package:flowy_infra_ui/widget/spacing.dart';
+import 'package:appflowy_ui/appflowy_ui.dart';
+import 'package:flowy_infra/theme_extension.dart';
+import 'package:flowy_infra_ui/flowy_infra_ui.dart';
+import 'package:flowy_infra_ui/style_widget/hover.dart';
import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
+import 'package:flutter_bloc/flutter_bloc.dart';
-class SearchRecentViewCell extends StatelessWidget {
+class SearchRecentViewCell extends StatefulWidget {
const SearchRecentViewCell({
super.key,
required this.icon,
@@ -19,33 +25,102 @@ class SearchRecentViewCell extends StatelessWidget {
final ViewPB view;
final VoidCallback onSelected;
+ @override
+ State<SearchRecentViewCell> createState() => _SearchRecentViewCellState();
+}
+
+class _SearchRecentViewCellState extends State<SearchRecentViewCell> {
+ final focusNode = FocusNode();
+
+ ViewPB get view => widget.view;
+
+ @override
+ void dispose() {
+ focusNode.dispose();
+ super.dispose();
+ }
+
@override
Widget build(BuildContext context) {
- return ListTile(
- dense: true,
- title: Row(
- children: [
- icon,
- const HSpace(6),
- Expanded(
- child: FlowyText(
- view.nameOrDefault,
- overflow: TextOverflow.ellipsis,
+ final theme = AppFlowyTheme.of(context),
+ textColor = theme.textColorScheme.primary;
+ final sapceM = theme.spacing.m, spaceL = theme.spacing.l;
+ final bloc = context.read<RecentViewsBloc>(), state = bloc.state;
+ final hoveredView = state.hoveredView;
+ final hovering = hoveredView == view;
+
+ return GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: () => _handleSelection(view.id),
+ child: Focus(
+ focusNode: focusNode,
+ onKeyEvent: (node, event) {
+ if (event is! KeyDownEvent) return KeyEventResult.ignored;
+ if (event.logicalKey == LogicalKeyboardKey.enter) {
+ _handleSelection(view.id);
+ return KeyEventResult.handled;
+ }
+ return KeyEventResult.ignored;
+ },
+ onFocusChange: (hasFocus) {
+ if (hasFocus && !hovering) {
+ bloc.add(RecentViewsEvent.hoverView(view));
+ }
+ },
+ child: FlowyHover(
+ onHover: (value) {
+ if (hoveredView == view) return;
+ bloc.add(RecentViewsEvent.hoverView(view));
+ },
+ style: HoverStyle(
+ borderRadius: BorderRadius.circular(8),
+ hoverColor: Theme.of(context).colorScheme.secondary,
+ foregroundColorOnHover: AFThemeExtension.of(context).textColor,
+ ),
+ isSelected: () => hovering,
+ child: Padding(
+ padding: EdgeInsets.symmetric(vertical: spaceL, horizontal: sapceM),
+ child: Row(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ widget.icon,
+ HSpace(12),
+ Flexible(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ view.nameOrDefault,
+ style: theme.textStyle.body.standard(color: textColor),
+ ),
+ buildPath(theme),
+ ],
+ ),
+ ),
+ ],
),
),
- ],
+ ),
+ ),
+ );
+ }
+
+ Widget buildPath(AppFlowyThemeData theme) {
+ return BlocProvider(
+ create: (context) => ViewAncestorBloc(view.id),
+ child: BlocBuilder<ViewAncestorBloc, ViewAncestorState>(
+ builder: (context, state) => state.buildPath(context),
+ ),
+ );
+ }
+
+ /// Helper to handle the selection action.
+ void _handleSelection(String id) {
+ widget.onSelected();
+ getIt<ActionNavigationBloc>().add(
+ ActionNavigationEvent.performAction(
+ action: NavigationAction(objectId: id),
),
- focusColor: Theme.of(context).colorScheme.primary.withValues(alpha: 0.1),
- hoverColor: Theme.of(context).colorScheme.primary.withValues(alpha: 0.1),
- onTap: () {
- onSelected();
-
- getIt<ActionNavigationBloc>().add(
- ActionNavigationEvent.performAction(
- action: NavigationAction(objectId: view.id),
- ),
- );
- },
);
}
}
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.dart
index 625882b3f4..56c9b2269a 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
@@ -1,27 +1,34 @@
import 'package:appflowy/generated/locale_keys.g.dart';
+import 'package:appflowy/mobile/presentation/search/mobile_search_cell.dart';
+import 'package:appflowy/mobile/presentation/search/mobile_view_ancestors.dart';
import 'package:appflowy/util/string_extension.dart';
import 'package:appflowy/workspace/application/command_palette/command_palette_bloc.dart';
import 'package:appflowy/workspace/application/command_palette/search_result_ext.dart';
import 'package:appflowy/workspace/application/command_palette/search_result_list_bloc.dart';
+import 'package:appflowy/workspace/application/view/prelude.dart';
+import 'package:appflowy/workspace/presentation/command_palette/command_palette.dart';
+import 'package:appflowy_backend/protobuf/flowy-search/result.pbenum.dart';
+import 'package:appflowy_ui/appflowy_ui.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra/theme_extension.dart';
import 'package:flowy_infra_ui/style_widget/hover.dart';
-import 'package:flowy_infra_ui/style_widget/text.dart';
import 'package:flowy_infra_ui/widget/spacing.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
+import 'page_preview.dart';
+
class SearchResultCell extends StatefulWidget {
const SearchResultCell({
super.key,
required this.item,
- this.isTrashed = false,
+ this.query,
this.isHovered = false,
});
final SearchResultItem item;
- final bool isTrashed;
+ final String? query;
final bool isHovered;
@override
@@ -32,6 +39,9 @@ class _SearchResultCellState extends State<SearchResultCell> {
bool _hasFocus = false;
final focusNode = FocusNode();
+ String get viewId => item.id;
+ SearchResultItem get item => widget.item;
+
@override
void dispose() {
focusNode.dispose();
@@ -41,93 +51,18 @@ class _SearchResultCellState extends State<SearchResultCell> {
/// Helper to handle the selection action.
void _handleSelection() {
context.read<SearchResultListBloc>().add(
- SearchResultListEvent.openPage(pageId: widget.item.id),
+ SearchResultListEvent.openPage(pageId: viewId),
);
}
- /// Helper to clean up preview text.
- String _cleanPreview(String preview) {
- return preview.replaceAll('\n', ' ').trim();
- }
-
@override
Widget build(BuildContext context) {
- final title = widget.item.displayName.orDefault(
+ final title = item.displayName.orDefault(
LocaleKeys.menuAppHeader_defaultNewPageName.tr(),
);
- final icon = widget.item.icon.getIcon();
- final cleanedPreview = _cleanPreview(widget.item.content);
- final hasPreview = cleanedPreview.isNotEmpty;
- final trashHintText =
- widget.isTrashed ? LocaleKeys.commandPalette_fromTrashHint.tr() : null;
-
- // Build the tile content based on preview availability.
- Widget tileContent;
- if (hasPreview) {
- tileContent = Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Row(
- children: [
- if (icon != null) ...[
- SizedBox(width: 24, child: icon),
- const HSpace(6),
- ],
- Flexible(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- if (widget.isTrashed)
- FlowyText(
- trashHintText!,
- color: AFThemeExtension.of(context)
- .textColor
- .withAlpha(175),
- fontSize: 10,
- ),
- FlowyText(
- title,
- overflow: TextOverflow.ellipsis,
- ),
- ],
- ),
- ),
- ],
- ),
- const VSpace(4),
- _DocumentPreview(preview: cleanedPreview),
- ],
- );
- } else {
- tileContent = Row(
- mainAxisSize: MainAxisSize.min,
- children: [
- if (icon != null) ...[
- SizedBox(width: 24, child: icon),
- const HSpace(6),
- ],
- Flexible(
- child: Column(
- mainAxisSize: MainAxisSize.min,
- children: [
- if (widget.isTrashed)
- FlowyText(
- trashHintText!,
- color:
- AFThemeExtension.of(context).textColor.withAlpha(175),
- fontSize: 10,
- ),
- FlowyText(
- title,
- overflow: TextOverflow.ellipsis,
- ),
- ],
- ),
- ),
- ],
- );
- }
+ final theme = AppFlowyTheme.of(context);
+ final textColor = theme.textColorScheme.primary;
return GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: _handleSelection,
@@ -145,7 +80,7 @@ class _SearchResultCellState extends State<SearchResultCell> {
setState(() {
context.read<SearchResultListBloc>().add(
SearchResultListEvent.onHoverResult(
- item: widget.item,
+ item: item,
userHovered: true,
),
);
@@ -156,7 +91,7 @@ class _SearchResultCellState extends State<SearchResultCell> {
onHover: (value) {
context.read<SearchResultListBloc>().add(
SearchResultListEvent.onHoverResult(
- item: widget.item,
+ item: item,
userHovered: true,
),
);
@@ -164,72 +99,136 @@ class _SearchResultCellState extends State<SearchResultCell> {
isSelected: () => _hasFocus || widget.isHovered,
style: HoverStyle(
borderRadius: BorderRadius.circular(8),
- hoverColor:
- Theme.of(context).colorScheme.primary.withValues(alpha: 0.1),
+ hoverColor: Theme.of(context).colorScheme.secondary,
foregroundColorOnHover: AFThemeExtension.of(context).textColor,
),
child: Padding(
- padding: const EdgeInsets.symmetric(vertical: 6, horizontal: 6),
- child: ConstrainedBox(
- constraints: const BoxConstraints(minHeight: 30),
- child: tileContent,
+ padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 12),
+ child: Row(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ SizedBox.square(
+ dimension: 24,
+ child: Center(child: buildIcon(theme)),
+ ),
+ HSpace(12),
+ Flexible(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ RichText(
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ text: buildHighLightSpan(
+ content: title,
+ normal:
+ theme.textStyle.body.standard(color: textColor),
+ highlight: theme.textStyle.body
+ .standard(color: textColor)
+ .copyWith(
+ backgroundColor:
+ theme.fillColorScheme.themeSelect,
+ ),
+ ),
+ ),
+ buildPath(theme),
+ ...buildSummary(theme),
+ ],
+ ),
+ ),
+ ],
),
),
),
),
);
}
-}
-class _DocumentPreview extends StatelessWidget {
- const _DocumentPreview({required this.preview});
+ Widget buildIcon(AppFlowyThemeData theme) {
+ final icon = item.icon;
+ final color = theme.iconColorScheme.secondary;
+ if (icon.ty == ResultIconTypePB.Emoji) {
+ return icon.getIcon(size: 20, iconColor: color) ?? SizedBox.shrink();
+ } else {
+ return icon.getIcon(size: 20, iconColor: color) ?? SizedBox.shrink();
+ }
+ }
- final String preview;
+ Widget buildPath(AppFlowyThemeData theme) {
+ return BlocProvider(
+ key: ValueKey(viewId),
+ create: (context) => ViewAncestorBloc(viewId),
+ child: BlocBuilder<ViewAncestorBloc, ViewAncestorState>(
+ builder: (context, state) => state.buildPath(context),
+ ),
+ );
+ }
- @override
- Widget build(BuildContext context) {
- // Combine the horizontal padding for clarity:
- return Padding(
- padding: const EdgeInsets.fromLTRB(30, 0, 16, 0),
- child: FlowyText.regular(
- preview,
- color: Theme.of(context).hintColor,
- fontSize: 12,
+ TextSpan buildHighLightSpan({
+ required String content,
+ required TextStyle normal,
+ required TextStyle highlight,
+ }) {
+ final queryText = (widget.query ?? '').trim();
+ if (queryText.isEmpty) {
+ return TextSpan(text: content, style: normal);
+ }
+ final contents = content.splitIncludeSeparator(queryText);
+ return TextSpan(
+ children: List.generate(contents.length, (index) {
+ final content = contents[index];
+ final isHighlight = content.toLowerCase() == queryText.toLowerCase();
+ return TextSpan(
+ text: content,
+ style: isHighlight ? highlight : normal,
+ );
+ }),
+ );
+ }
+
+ List<Widget> buildSummary(AppFlowyThemeData theme) {
+ if (item.content.isEmpty) return [];
+ return [
+ VSpace(4),
+ RichText(
maxLines: 3,
overflow: TextOverflow.ellipsis,
+ text: buildHighLightSpan(
+ content: item.content,
+ normal: theme.textStyle.caption
+ .standard(color: theme.textColorScheme.secondary),
+ highlight: theme.textStyle.caption
+ .standard(color: theme.textColorScheme.primary)
+ .copyWith(
+ backgroundColor: theme.fillColorScheme.themeSelect,
+ ),
+ ),
),
- );
+ ];
}
}
class SearchResultPreview extends StatelessWidget {
const SearchResultPreview({
super.key,
- required this.data,
+ required this.item,
});
- final SearchResultItem data;
+ final SearchResultItem item;
@override
Widget build(BuildContext context) {
- return SingleChildScrollView(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Opacity(
- opacity: 0.5,
- child: FlowyText(
- LocaleKeys.commandPalette_pagePreview.tr(),
- fontSize: 12,
- ),
- ),
- const VSpace(6),
- FlowyText(
- data.content,
- maxLines: null,
- ),
- ],
- ),
+ return FutureBuilder(
+ future: ViewBackendService.getView(item.id),
+ builder: (context, snapshot) {
+ if (!snapshot.hasData) {
+ return const Center(child: CircularProgressIndicator());
+ }
+ final view = snapshot.data?.toNullable();
+ if (view == null) return NoSearchResultsHint();
+
+ return PagePreview(view: view);
+ },
);
}
}
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.dart
index d90888e3e9..cc1649690d 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
@@ -3,6 +3,10 @@ import 'package:appflowy/workspace/application/action_navigation/action_navigati
import 'package:appflowy/workspace/application/action_navigation/navigation_action.dart';
import 'package:appflowy/workspace/application/command_palette/command_palette_bloc.dart';
import 'package:appflowy/workspace/application/command_palette/search_result_list_bloc.dart';
+import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
+import 'package:appflowy/workspace/presentation/command_palette/widgets/search_ask_ai_entrance.dart';
+import 'package:appflowy_backend/protobuf/flowy-user/workspace.pbenum.dart';
+import 'package:appflowy_ui/appflowy_ui.dart';
import 'package:flutter/material.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
@@ -11,10 +15,7 @@ import 'package:appflowy_backend/protobuf/flowy-search/result.pb.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
-import 'package:flutter_animate/flutter_animate.dart';
-
import 'search_result_cell.dart';
-import 'search_summary_cell.dart';
class SearchResultList extends StatefulWidget {
const SearchResultList({
@@ -47,148 +48,110 @@ class _SearchResultListState extends State<SearchResultList> {
super.dispose();
}
- Widget _buildSectionHeader(String title) => Padding(
- padding: const EdgeInsets.symmetric(vertical: 8) +
- const EdgeInsets.only(left: 8),
- child: Opacity(
- opacity: 0.6,
- child: FlowyText(title, fontSize: 12),
- ),
- );
-
- Widget _buildAIOverviewSection(BuildContext context) {
- final state = context.read<CommandPaletteBloc>().state;
-
- if (state.generatingAIOverview) {
- return Row(
- children: [
- _buildSectionHeader(LocaleKeys.commandPalette_aiOverview.tr()),
- const HSpace(10),
- const AIOverviewIndicator(),
- ],
- );
- }
-
- if (widget.resultSummaries.isNotEmpty) {
- if (!bloc.state.userHovered) {
- WidgetsBinding.instance.addPostFrameCallback(
- (_) {
- bloc.add(
- SearchResultListEvent.onHoverSummary(
- summary: widget.resultSummaries[0],
- userHovered: false,
+ @override
+ Widget build(BuildContext context) {
+ return BlocProvider.value(
+ value: bloc,
+ child: BlocListener<SearchResultListBloc, SearchResultListState>(
+ listener: (context, state) {
+ if (state.openPageId != null) {
+ FlowyOverlay.pop(context);
+ getIt<ActionNavigationBloc>().add(
+ ActionNavigationEvent.performAction(
+ action: NavigationAction(objectId: state.openPageId!),
),
);
+ }
+ },
+ child: BlocBuilder<SearchResultListBloc, SearchResultListState>(
+ builder: (context, state) {
+ final showPreview = state.hoveredResult != null;
+ return Row(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Flexible(flex: 2, child: _buildResultsSection(context)),
+ if (showPreview) ...[
+ AFDivider(axis: Axis.vertical),
+ Flexible(child: const SearchCellPreview()),
+ ],
+ ],
+ );
},
- );
- }
-
- return Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- _buildSectionHeader(LocaleKeys.commandPalette_aiOverview.tr()),
- ListView.separated(
- physics: const NeverScrollableScrollPhysics(),
- shrinkWrap: true,
- itemCount: widget.resultSummaries.length,
- separatorBuilder: (_, __) => const Divider(height: 0),
- itemBuilder: (_, index) => SearchSummaryCell(
- summary: widget.resultSummaries[index],
- isHovered: bloc.state.hoveredSummary != null,
- ),
- ),
- ],
- );
- }
-
- return const SizedBox.shrink();
+ ),
+ ),
+ );
}
- Widget _buildResultsSection(BuildContext context) {
- return Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- const SizedBox(height: 8),
- _buildSectionHeader(LocaleKeys.commandPalette_bestMatches.tr()),
- ListView.separated(
- physics: const NeverScrollableScrollPhysics(),
- shrinkWrap: true,
- itemCount: widget.resultItems.length,
- separatorBuilder: (_, __) => const Divider(height: 0),
- itemBuilder: (_, index) {
- final item = widget.resultItems[index];
- return SearchResultCell(
- item: item,
- isTrashed: widget.trash.any((t) => t.id == item.id),
- isHovered: bloc.state.hoveredResult?.id == item.id,
- );
- },
+ Widget _buildSectionHeader(BuildContext context) {
+ final theme = AppFlowyTheme.of(context);
+ return Container(
+ height: 20,
+ padding: const EdgeInsets.symmetric(horizontal: 8),
+ child: Text(
+ LocaleKeys.commandPalette_bestMatches.tr(),
+ style: theme.textStyle.body.enhanced(
+ color: theme.textColorScheme.secondary,
),
- ],
+ ),
);
}
- @override
- Widget build(BuildContext context) {
- return Padding(
- padding: const EdgeInsets.symmetric(horizontal: 6),
- child: BlocProvider.value(
- value: bloc,
- child: BlocListener<SearchResultListBloc, SearchResultListState>(
- listener: (context, state) {
- if (state.openPageId != null) {
- FlowyOverlay.pop(context);
- getIt<ActionNavigationBloc>().add(
- ActionNavigationEvent.performAction(
- action: NavigationAction(objectId: state.openPageId!),
- ),
- );
- }
- },
- child: Row(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Flexible(
- flex: 7,
- child: BlocBuilder<SearchResultListBloc, SearchResultListState>(
- buildWhen: (previous, current) =>
- previous.hoveredResult != current.hoveredResult ||
- previous.hoveredSummary != current.hoveredSummary,
- builder: (context, state) {
- return ListView(
- shrinkWrap: true,
- physics: const ClampingScrollPhysics(),
+ Widget _buildResultsSection(BuildContext context) {
+ final workspaceState = context.read<UserWorkspaceBloc?>()?.state;
+ final showAskingAI =
+ workspaceState?.userProfile.workspaceType == WorkspaceTypePB.ServerW;
+ if (widget.resultItems.isEmpty) return const SizedBox.shrink();
+ final trashIds = widget.trash.map((e) => e.id).toSet();
+ final resultItems = widget.resultItems
+ .where((item) => !trashIds.contains(item.id))
+ .toList();
+ return ScrollControllerBuilder(
+ builder: (context, controller) {
+ 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: [
- _buildAIOverviewSection(context),
- const VSpace(10),
- if (widget.resultItems.isNotEmpty)
- _buildResultsSection(context),
+ _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,
+ );
+ },
+ ),
],
- );
- },
- ),
- ),
- const HSpace(10),
- if (widget.resultItems
- .any((item) => item.content.isNotEmpty)) ...[
- const VerticalDivider(
- thickness: 1.0,
- ),
- Flexible(
- flex: 3,
- child: Padding(
- padding: const EdgeInsets.symmetric(
- horizontal: 8,
- vertical: 16,
),
- child: const SearchCellPreview(),
),
- ),
- ],
- ],
+ ],
+ ),
+ ),
),
- ),
- ),
+ );
+ },
);
}
}
@@ -200,79 +163,11 @@ class SearchCellPreview extends StatelessWidget {
Widget build(BuildContext context) {
return BlocBuilder<SearchResultListBloc, SearchResultListState>(
builder: (context, state) {
- if (state.hoveredSummary != null) {
- return SearchSummaryPreview(summary: state.hoveredSummary!);
- } else if (state.hoveredResult != null) {
- return SearchResultPreview(data: state.hoveredResult!);
+ if (state.hoveredResult != null) {
+ return SearchResultPreview(item: state.hoveredResult!);
}
return const SizedBox.shrink();
},
);
}
}
-
-class AIOverviewIndicator extends StatelessWidget {
- const AIOverviewIndicator({
- super.key,
- this.duration = const Duration(seconds: 1),
- });
-
- final Duration duration;
-
- @override
- Widget build(BuildContext context) {
- final slice = Duration(milliseconds: duration.inMilliseconds ~/ 5);
- return SelectionContainer.disabled(
- child: SizedBox(
- height: 20,
- width: 100,
- child: SeparatedRow(
- separatorBuilder: () => const HSpace(4),
- children: [
- buildDot(const Color(0xFF9327FF))
- .animate(onPlay: (controller) => controller.repeat())
- .slideY(duration: slice, begin: 0, end: -1)
- .then()
- .slideY(begin: -1, end: 1)
- .then()
- .slideY(begin: 1, end: 0)
- .then()
- .slideY(duration: slice * 2, begin: 0, end: 0),
- buildDot(const Color(0xFFFB006D))
- .animate(onPlay: (controller) => controller.repeat())
- .slideY(duration: slice, begin: 0, end: 0)
- .then()
- .slideY(begin: 0, end: -1)
- .then()
- .slideY(begin: -1, end: 1)
- .then()
- .slideY(begin: 1, end: 0)
- .then()
- .slideY(begin: 0, end: 0),
- buildDot(const Color(0xFFFFCE00))
- .animate(onPlay: (controller) => controller.repeat())
- .slideY(duration: slice * 2, begin: 0, end: 0)
- .then()
- .slideY(duration: slice, begin: 0, end: -1)
- .then()
- .slideY(begin: -1, end: 1)
- .then()
- .slideY(begin: 1, end: 0),
- ],
- ),
- ),
- );
- }
-
- Widget buildDot(Color color) {
- return SizedBox.square(
- dimension: 4,
- child: DecoratedBox(
- decoration: BoxDecoration(
- color: color,
- borderRadius: BorderRadius.circular(2),
- ),
- ),
- );
- }
-}
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/search_summary_cell.dart b/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/search_summary_cell.dart
index 0da73bee4f..e74529586b 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/search_summary_cell.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/search_summary_cell.dart
@@ -1,142 +1,441 @@
+import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
-import 'package:appflowy/plugins/ai_chat/presentation/message/ai_markdown_text.dart';
+import 'package:appflowy/mobile/presentation/search/mobile_search_cell.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/command_palette/command_palette_bloc.dart';
import 'package:appflowy/workspace/application/command_palette/search_result_ext.dart';
-import 'package:appflowy/workspace/application/command_palette/search_result_list_bloc.dart';
-import 'package:easy_localization/easy_localization.dart';
-import 'package:flowy_infra/theme_extension.dart';
-import 'package:flowy_infra_ui/style_widget/hover.dart';
+import 'package:appflowy_editor/appflowy_editor.dart';
+import 'package:appflowy_ui/appflowy_ui.dart';
+import 'package:easy_localization/easy_localization.dart' hide TextDirection;
import 'package:flutter/material.dart';
import 'package:appflowy_backend/protobuf/flowy-search/result.pb.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
-class SearchSummaryCell extends StatelessWidget {
+class SearchSummaryCell extends StatefulWidget {
const SearchSummaryCell({
required this.summary,
- required this.isHovered,
+ required this.maxWidth,
+ required this.theme,
super.key,
});
final SearchSummaryPB summary;
- final bool isHovered;
+ final double maxWidth;
+ final AppFlowyThemeData theme;
@override
- Widget build(BuildContext context) {
- return FlowyHover(
- isSelected: () => isHovered,
- onHover: (value) {
- context.read<SearchResultListBloc>().add(
- SearchResultListEvent.onHoverSummary(
- summary: summary,
- userHovered: true,
- ),
- );
- },
- style: HoverStyle(
- borderRadius: BorderRadius.circular(8),
- hoverColor:
- Theme.of(context).colorScheme.primary.withValues(alpha: 0.1),
- foregroundColorOnHover: AFThemeExtension.of(context).textColor,
- ),
- child: Padding(
- padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
- child: FlowyText(
- summary.content,
- maxLines: 10,
- ),
- ),
- );
- }
+ State<SearchSummaryCell> createState() => _SearchSummaryCellState();
}
-class SearchSummaryPreview extends StatelessWidget {
- const SearchSummaryPreview({
- required this.summary,
- super.key,
- });
+class _SearchSummaryCellState extends State<SearchSummaryCell> {
+ late TextPainter _painter;
+ late _TextInfo _textInfo = _TextInfo.normal(summary.content);
+ bool tappedShowMore = false;
+ final maxLines = 5;
+ final popoverController = PopoverController();
+ bool isLinkHovering = false, isReferenceHovering = false;
- final SearchSummaryPB summary;
+ SearchSummaryPB get summary => widget.summary;
+ double get maxWidth => widget.maxWidth;
+ AppFlowyThemeData get theme => widget.theme;
+
+ TextStyle get textStyle => theme.textStyle.body.standard(
+ color: theme.textColorScheme.primary,
+ );
+
+ TextStyle get showMoreStyle => theme.textStyle.body.standard(
+ color: theme.textColorScheme.secondary,
+ );
+
+ TextStyle get showMoreUnderlineStyle => theme.textStyle.body.underline(
+ color: theme.textColorScheme.secondary,
+ );
+
+ @override
+ void initState() {
+ super.initState();
+ refreshTextPainter();
+ }
+
+ @override
+ void didUpdateWidget(SearchSummaryCell oldWidget) {
+ super.didUpdateWidget(oldWidget);
+ if (oldWidget.maxWidth != maxWidth) {
+ refreshTextPainter();
+ }
+ }
+
+ @override
+ void dispose() {
+ _painter.dispose();
+ popoverController.close();
+ super.dispose();
+ }
@override
Widget build(BuildContext context) {
- return SingleChildScrollView(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- if (summary.highlights.isNotEmpty) ...[
- Opacity(
- opacity: 0.5,
- child: FlowyText(
- LocaleKeys.commandPalette_aiOverviewMoreDetails.tr(),
- fontSize: 12,
+ final showReference = summary.sources.isNotEmpty;
+ final query = summary.highlights.isEmpty
+ ? context.read<CommandPaletteBloc?>()?.state.query
+ : summary.highlights;
+
+ return _textInfo.build(
+ context: context,
+ normal: textStyle,
+ more: showMoreStyle,
+ query: query ?? '',
+ moreUnderline: showMoreUnderlineStyle,
+ showMore: () {
+ setState(() {
+ tappedShowMore = true;
+ _textInfo = _TextInfo.normal(summary.content);
+ });
+ },
+ normalWidgetSpan: showReference
+ ? WidgetSpan(
+ child: Padding(
+ padding: const EdgeInsets.only(left: 4),
+ child: MouseRegion(
+ cursor: SystemMouseCursors.click,
+ onEnter: (event) {
+ if (!isLinkHovering) {
+ isLinkHovering = true;
+ showPopover();
+ }
+ },
+ onExit: (event) {
+ if (isLinkHovering) {
+ isLinkHovering = false;
+ tryToHidePopover();
+ }
+ },
+ child: buildReferenceIcon(),
+ ),
),
- ),
- const VSpace(6),
- SearchSummaryDetail(text: summary.highlights),
- const VSpace(36),
- ],
+ )
+ : null,
+ );
+ }
- Opacity(
- opacity: 0.5,
- child: FlowyText(
- LocaleKeys.commandPalette_aiOverviewSource.tr(),
- fontSize: 12,
+ Widget buildReferenceIcon() {
+ final iconSize = Size(21, 15), placeholderHeight = iconSize.height + 10.0;
+ return AppFlowyPopover(
+ offset: Offset(0, -iconSize.height),
+ constraints:
+ BoxConstraints(maxWidth: 360, maxHeight: 420 + placeholderHeight),
+ direction: PopoverDirection.bottomWithCenterAligned,
+ margin: EdgeInsets.zero,
+ controller: popoverController,
+ decorationColor: Colors.transparent,
+ popoverDecoration: BoxDecoration(),
+ popupBuilder: (popoverContext) => MouseRegion(
+ onEnter: (event) {
+ if (!isReferenceHovering) {
+ isReferenceHovering = true;
+ }
+ },
+ onExit: (event) {
+ if (isReferenceHovering) {
+ isReferenceHovering = false;
+ tryToHidePopover();
+ }
+ },
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ SizedBox(height: placeholderHeight),
+ Flexible(
+ child: ReferenceSources(
+ summary.sources,
+ onClose: () {
+ hidePopover();
+ if (context.mounted) FlowyOverlay.pop(context);
+ },
+ ),
),
- ),
- // Sources
- const VSpace(6),
- ...summary.sources.map((e) => SearchSummarySource(source: e)),
- ],
+ ],
+ ),
+ ),
+ child: Container(
+ width: iconSize.width,
+ height: iconSize.height,
+ decoration: BoxDecoration(
+ color: Theme.of(context).colorScheme.secondary,
+ borderRadius: BorderRadius.circular(6),
+ ),
+ child: FlowySvg(
+ FlowySvgs.toolbar_link_m,
+ color: theme.iconColorScheme.primary,
+ size: Size.square(10),
+ ),
),
);
}
+
+ void showPopover() {
+ keepEditorFocusNotifier.increase();
+ popoverController.show();
+ }
+
+ void hidePopover() {
+ popoverController.close();
+ keepEditorFocusNotifier.decrease();
+ }
+
+ void tryToHidePopover() {
+ if (isLinkHovering || isReferenceHovering) return;
+ Future.delayed(Duration(milliseconds: 500), () {
+ if (!context.mounted) return;
+ if (isLinkHovering || isReferenceHovering) return;
+ hidePopover();
+ });
+ }
+
+ void refreshTextPainter() {
+ final content = summary.content,
+ ellipsis = ' ...${LocaleKeys.search_seeMore.tr()}';
+ if (!tappedShowMore) {
+ _painter = TextPainter(
+ text: TextSpan(text: content, style: textStyle),
+ textDirection: TextDirection.ltr,
+ maxLines: maxLines,
+ ellipsis: ellipsis,
+ );
+ _painter.layout(maxWidth: maxWidth);
+ if (_painter.didExceedMaxLines) {
+ final lines = _painter.computeLineMetrics();
+ final lastLine = lines.last;
+ final offset = Offset(
+ lastLine.left + lastLine.width,
+ lines.map((e) => e.height).reduce((a, b) => a + b),
+ );
+ final range = _painter.getPositionForOffset(offset);
+ final text = content.substring(0, range.offset);
+ _textInfo = _TextInfo.overflow(text);
+ } else {
+ _textInfo = _TextInfo.normal(content);
+ }
+ }
+ }
}
-class SearchSummaryDetail extends StatelessWidget {
- const SearchSummaryDetail({
- required this.text,
- super.key,
- });
+class _TextInfo {
+ _TextInfo({required this.text, required this.isOverflow});
+
+ _TextInfo.normal(this.text) : isOverflow = false;
+
+ _TextInfo.overflow(this.text) : isOverflow = true;
final String text;
+ final bool isOverflow;
- @override
- Widget build(BuildContext context) {
- return SizedBox(
- width: double.infinity,
- child: AIMarkdownText(markdown: text),
+ Widget build({
+ required BuildContext context,
+ required TextStyle normal,
+ required TextStyle more,
+ required TextStyle moreUnderline,
+ required VoidCallback showMore,
+ required String query,
+ WidgetSpan? normalWidgetSpan,
+ }) {
+ final theme = AppFlowyTheme.of(context);
+ if (isOverflow) {
+ return SelectionArea(
+ child: Text.rich(
+ TextSpan(
+ children: [
+ _buildHighLightSpan(
+ content: text,
+ normal: normal,
+ query: query,
+ highlight: normal.copyWith(
+ backgroundColor: theme.fillColorScheme.themeSelect,
+ ),
+ ),
+ TextSpan(
+ text: ' ...',
+ style: normal,
+ ),
+ WidgetSpan(
+ alignment: PlaceholderAlignment.middle,
+ child: AFBaseButton(
+ padding: EdgeInsets.zero,
+ builder: (context, isHovering, disabled) =>
+ SelectionContainer.disabled(
+ child: Text(
+ LocaleKeys.search_seeMore.tr(),
+ style: isHovering ? moreUnderline : more,
+ ),
+ ),
+ borderColor: (_, __, ___, ____) => Colors.transparent,
+ borderRadius: 0,
+ onTap: showMore,
+ ),
+ ),
+ ],
+ ),
+ ),
+ );
+ } else {
+ return SelectionArea(
+ child: Text.rich(
+ TextSpan(
+ children: [
+ _buildHighLightSpan(
+ content: text,
+ normal: normal,
+ query: query,
+ highlight: normal.copyWith(
+ backgroundColor: theme.fillColorScheme.themeSelect,
+ ),
+ ),
+ if (normalWidgetSpan != null) normalWidgetSpan,
+ ],
+ ),
+ ),
+ );
+ }
+ }
+
+ TextSpan _buildHighLightSpan({
+ required String content,
+ required TextStyle normal,
+ required TextStyle highlight,
+ String? query,
+ }) {
+ final queryText = (query ?? '').trim();
+ if (queryText.isEmpty) {
+ return TextSpan(text: content, style: normal);
+ }
+ final contents = content.splitIncludeSeparator(queryText);
+ return TextSpan(
+ children: List.generate(contents.length, (index) {
+ final content = contents[index];
+ final isHighlight = content.toLowerCase() == queryText.toLowerCase();
+ return TextSpan(
+ text: content,
+ style: isHighlight ? highlight : normal,
+ );
+ }),
);
}
}
-class SearchSummarySource extends StatelessWidget {
- const SearchSummarySource({
- required this.source,
+class ReferenceSources extends StatelessWidget {
+ const ReferenceSources(
+ this.sources, {
super.key,
+ this.onClose,
});
- final SearchSourcePB source;
+ final List<SearchSourcePB> sources;
+ final VoidCallback? onClose;
@override
Widget build(BuildContext context) {
- final icon = source.icon.getIcon();
- return FlowyTooltip(
- message: LocaleKeys.commandPalette_clickToOpenPage.tr(),
- child: SizedBox(
- height: 40,
- child: FlowyButton(
- leftIcon: icon,
- hoverColor:
- Theme.of(context).colorScheme.primary.withValues(alpha: 0.1),
- text: FlowyText(source.displayName),
- onTap: () {
- context.read<SearchResultListBloc>().add(
- SearchResultListEvent.openPage(pageId: source.id),
+ final theme = AppFlowyTheme.of(context);
+ return Container(
+ decoration: ShapeDecoration(
+ color: theme.surfaceColorScheme.primary,
+ shape: RoundedRectangleBorder(
+ borderRadius: BorderRadius.circular(theme.spacing.m),
+ ),
+ shadows: theme.shadow.small,
+ ),
+ padding: EdgeInsets.all(8),
+ child: SingleChildScrollView(
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Padding(
+ padding: EdgeInsets.symmetric(vertical: 4, horizontal: 8),
+ child: Text(
+ LocaleKeys.commandPalette_aiOverviewSource.tr(),
+ style: theme.textStyle.body.enhanced(
+ color: theme.textColorScheme.secondary,
+ ),
+ ),
+ ),
+ ListView.separated(
+ shrinkWrap: true,
+ physics: const NeverScrollableScrollPhysics(),
+ itemBuilder: (context, index) {
+ final source = sources[index];
+ final displayName = source.displayName.isEmpty
+ ? LocaleKeys.menuAppHeader_defaultNewPageName.tr()
+ : source.displayName;
+ final sapceM = theme.spacing.m, spaceL = theme.spacing.l;
+
+ return AFBaseButton(
+ borderRadius: sapceM,
+ onTap: () {
+ getIt<ActionNavigationBloc>().add(
+ ActionNavigationEvent.performAction(
+ action: NavigationAction(objectId: source.id),
+ ),
+ );
+ onClose?.call();
+ },
+ padding: EdgeInsets.symmetric(
+ vertical: spaceL,
+ horizontal: sapceM,
+ ),
+ backgroundColor: (context, isHovering, disable) {
+ if (isHovering) {
+ return Theme.of(context).colorScheme.secondary;
+ }
+ return theme.fillColorScheme.transparent;
+ },
+ borderColor: (context, isHovering, disabled, isFocused) =>
+ theme.fillColorScheme.transparent,
+ builder: (context, isHovering, disabled) => Row(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ SizedBox.square(
+ dimension: 20,
+ child: Center(child: buildIcon(source.icon, theme)),
+ ),
+ HSpace(8),
+ Flexible(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Text(
+ displayName,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: theme.textStyle.body.standard(
+ color: theme.textColorScheme.primary,
+ ),
+ ),
+ ],
+ ),
+ ),
+ ],
+ ),
);
- },
+ },
+ separatorBuilder: (context, index) => AFDivider(),
+ itemCount: sources.length,
+ ),
+ ],
),
),
);
}
+
+ Widget buildIcon(ResultIconPB icon, AppFlowyThemeData theme) {
+ if (icon.ty == ResultIconTypePB.Emoji) {
+ return icon.getIcon(size: 16, lineHeight: 20 / 16) ?? SizedBox.shrink();
+ } else {
+ return icon.getIcon(size: 20, iconColor: theme.iconColorScheme.primary) ??
+ SizedBox.shrink();
+ }
+ }
}
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/sidebar.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/sidebar.dart
index 9c19184217..1341c344e8 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/sidebar.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/sidebar.dart
@@ -516,7 +516,12 @@ class _SidebarSearchButton extends StatelessWidget {
onTap: () {
// exit editing mode when doing search to avoid the toolbar showing up
EditorNotification.exitEditing().post();
- CommandPalette.of(context).toggle();
+ final workspaceBloc = context.read<UserWorkspaceBloc?>();
+ final spaceBloc = context.read<SpaceBloc?>();
+ CommandPalette.of(context).toggle(
+ workspaceBloc: workspaceBloc,
+ spaceBloc: spaceBloc,
+ );
},
leftIcon: const FlowySvg(FlowySvgs.search_s),
iconPadding: 12.0,
diff --git a/frontend/appflowy_flutter/packages/flowy_infra_ui/lib/style_widget/scrollbar.dart b/frontend/appflowy_flutter/packages/flowy_infra_ui/lib/style_widget/scrollbar.dart
index 01111293ec..e55fd16ccd 100644
--- a/frontend/appflowy_flutter/packages/flowy_infra_ui/lib/style_widget/scrollbar.dart
+++ b/frontend/appflowy_flutter/packages/flowy_infra_ui/lib/style_widget/scrollbar.dart
@@ -50,3 +50,32 @@ class _FlowyScrollbarState extends State<FlowyScrollbar> {
);
}
}
+
+class ScrollControllerBuilder extends StatefulWidget {
+ const ScrollControllerBuilder({super.key, required this.builder});
+ final ScrollControllerWidgetBuilder builder;
+
+ @override
+ State<ScrollControllerBuilder> createState() =>
+ _ScrollControllerBuilderState();
+}
+
+class _ScrollControllerBuilderState extends State<ScrollControllerBuilder> {
+ final ScrollController controller = ScrollController();
+
+ @override
+ void dispose() {
+ controller.dispose();
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return widget.builder(context, controller);
+ }
+}
+
+typedef ScrollControllerWidgetBuilder = Widget Function(
+ BuildContext context,
+ ScrollController controller,
+);
diff --git a/frontend/resources/flowy_icons/20x/ai_searching_icon.svg b/frontend/resources/flowy_icons/20x/ai_searching_icon.svg
new file mode 100644
index 0000000000..971471fd38
--- /dev/null
+++ b/frontend/resources/flowy_icons/20x/ai_searching_icon.svg
@@ -0,0 +1,14 @@
+<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
+<path d="M8.03338 4.65784C8.37931 3.78072 9.62067 3.78072 9.9666 4.65785L11.0386 7.37598C11.1442 7.64377 11.3562 7.85575 11.624 7.96136L14.3422 9.03338C15.2193 9.37931 15.2193 10.6207 14.3422 10.9666L11.624 12.0386C11.3562 12.1442 11.1442 12.3562 11.0386 12.624L9.9666 15.3422C9.62066 16.2193 8.37931 16.2193 8.03338 15.3422L6.96136 12.624C6.85574 12.3562 6.64377 12.1442 6.37598 12.0386L3.65784 10.9666C2.78072 10.6207 2.78072 9.37931 3.65785 9.03338L6.37598 7.96136C6.64377 7.85574 6.85575 7.64377 6.96136 7.37598L8.03338 4.65784Z" stroke="url(#paint0_linear_12729_12921)"/>
+<path d="M14.7235 14.1853C14.826 13.9382 15.1768 13.9382 15.2792 14.1853L15.412 14.5076C15.6152 14.9979 16.0056 15.3874 16.496 15.5906L16.8163 15.7234C17.0631 15.826 17.0624 16.1758 16.8153 16.2781L16.4931 16.4119C16.0022 16.6151 15.6122 17.0051 15.4091 17.4959L15.2772 17.8142C15.1749 18.0615 14.8249 18.0615 14.7226 17.8142L14.5897 17.4929C14.3866 17.0018 13.996 16.6112 13.5048 16.408L13.1854 16.2761C12.9382 16.1738 12.9382 15.8238 13.1854 15.7214L13.5077 15.5877C13.998 15.3846 14.3874 14.9948 14.5907 14.5046L14.7235 14.1853ZM14.7235 2.18531C14.826 1.93825 15.1768 1.93821 15.2792 2.18531L15.412 2.50757C15.6152 2.99793 16.0056 3.38737 16.496 3.59058L16.8163 3.7234C17.0631 3.82603 17.0624 4.1758 16.8153 4.27808L16.4931 4.41187C16.0022 4.61512 15.6122 5.00506 15.4091 5.49586L15.2772 5.81422C15.1749 6.0615 14.8249 6.06147 14.7226 5.81422L14.5897 5.49293C14.3866 5.00175 13.996 4.61121 13.5048 4.40797L13.1854 4.27613C12.9382 4.17381 12.9382 3.82384 13.1854 3.72144L13.5077 3.58765C13.998 3.38457 14.3874 2.99482 14.5907 2.50465L14.7235 2.18531Z" fill="url(#paint1_linear_12729_12921)"/>
+<defs>
+<linearGradient id="paint0_linear_12729_12921" x1="5" y1="17" x2="18.5897" y2="10.1016" gradientUnits="userSpaceOnUse">
+<stop stop-color="#8032FF"/>
+<stop offset="1" stop-color="#FB3DFF"/>
+</linearGradient>
+<linearGradient id="paint1_linear_12729_12921" x1="10" y1="19" x2="16.9581" y2="19.0194" gradientUnits="userSpaceOnUse">
+<stop stop-color="#8032FF"/>
+<stop offset="1" stop-color="#FB3DFF"/>
+</linearGradient>
+</defs>
+</svg>
diff --git a/frontend/resources/flowy_icons/20x/search_arrow_right.svg b/frontend/resources/flowy_icons/20x/search_arrow_right.svg
new file mode 100644
index 0000000000..01a64d5f55
--- /dev/null
+++ b/frontend/resources/flowy_icons/20x/search_arrow_right.svg
@@ -0,0 +1,3 @@
+<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
+<path d="M4.6665 10H15.3332M15.3332 10L11.3332 6M15.3332 10L11.3332 14" stroke="#6F748C" stroke-linecap="round" stroke-linejoin="round"/>
+</svg>
diff --git a/frontend/resources/flowy_icons/20x/search_clear.svg b/frontend/resources/flowy_icons/20x/search_clear.svg
new file mode 100644
index 0000000000..764a75cb64
--- /dev/null
+++ b/frontend/resources/flowy_icons/20x/search_clear.svg
@@ -0,0 +1,3 @@
+<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
+<path d="M10 2C14.4183 2 18 5.58172 18 10C18 14.4183 14.4183 18 10 18C5.58172 18 2 14.4183 2 10C2 5.58172 5.58172 2 10 2ZM12.8232 7.17676C12.5872 6.94067 12.204 6.94092 11.9678 7.17676L10 9.14453L8.03223 7.17676C7.79598 6.94091 7.41285 6.94067 7.17676 7.17676C6.94067 7.41285 6.94092 7.79598 7.17676 8.03223L9.14453 10L7.17676 11.9678C6.94091 12.204 6.94067 12.5872 7.17676 12.8232C7.41285 13.0593 7.79598 13.0591 8.03223 12.8232L10 10.8555L11.9678 12.8232C12.204 13.0591 12.5872 13.0593 12.8232 12.8232C13.0593 12.5872 13.0591 12.204 12.8232 11.9678L10.8555 10L12.8232 8.03223C13.0591 7.79598 13.0593 7.41285 12.8232 7.17676Z" fill="#B5BBD3"/>
+</svg>
diff --git a/frontend/resources/flowy_icons/20x/search_icon.svg b/frontend/resources/flowy_icons/20x/search_icon.svg
new file mode 100644
index 0000000000..73d9aae054
--- /dev/null
+++ b/frontend/resources/flowy_icons/20x/search_icon.svg
@@ -0,0 +1,3 @@
+<svg width="20" height="21" viewBox="0 0 20 21" fill="none" xmlns="http://www.w3.org/2000/svg">
+<path d="M15.8553 16.8427C16.0516 17.0369 16.3681 17.0353 16.5624 16.839C16.7566 16.6428 16.755 16.3262 16.5588 16.1319L15.8553 16.8427ZM15.2946 9.9746H14.7946C14.7946 12.7242 12.5413 14.9619 9.75082 14.9619V15.4619V15.9619C13.0839 15.9619 15.7946 13.2861 15.7946 9.9746H15.2946ZM9.75082 15.4619V14.9619C6.96037 14.9619 4.70703 12.7242 4.70703 9.9746H4.20703H3.70703C3.70703 13.2861 6.41777 15.9619 9.75082 15.9619V15.4619ZM4.20703 9.9746H4.70703C4.70703 7.22501 6.96037 4.9873 9.75082 4.9873V4.4873V3.9873C6.41777 3.9873 3.70703 6.66309 3.70703 9.9746H4.20703ZM9.75082 4.4873V4.9873C12.5413 4.9873 14.7946 7.22501 14.7946 9.9746H15.2946H15.7946C15.7946 6.66309 13.0839 3.9873 9.75082 3.9873V4.4873ZM13.2303 13.5409L12.8785 13.8963L15.8553 16.8427L16.207 16.4873L16.5588 16.1319L13.582 13.1855L13.2303 13.5409Z" fill="#6F748C"/>
+</svg>
diff --git a/frontend/resources/translations/en.json b/frontend/resources/translations/en.json
index fbba439872..d98c0682e1 100644
--- a/frontend/resources/translations/en.json
+++ b/frontend/resources/translations/en.json
@@ -2358,9 +2358,12 @@
"searchOrAskAI": "Search or ask AI",
"askAIAnything": "Ask AI anything",
"askAIFor": "Ask AI",
+ "searching": "Searching...",
"noResultForSearching": "No matches found",
"noResultForSearchingHint": "Try different questions or keywords.\n Some pages may be in the Trash.",
+ "noResultForSearchingHintWithoutTrash": "Try different questions or keywords\n Some pages may be in the ",
"bestMatch": "Best match",
+ "seeMore": "See more",
"placeholder": {
"actions": "Search actions..."
}
@@ -2806,6 +2809,7 @@
"aiOverview": "AI overview",
"aiOverviewSource": "Reference sources",
"aiOverviewMoreDetails": "More details",
+ "aiAskFollowUp": "Ask follow-up",
"pagePreview": "Content preview",
"clickToOpenPage": "Click to open page",
"recentHistory": "Recent history",
@@ -2815,7 +2819,10 @@
"betaTooltip": "We currently only support searching for pages and content in documents",
"fromTrashHint": "From trash",
"noResultsHint": "We didn't find what you're looking for, try searching for another term.",
- "clearSearchTooltip": "Clear search field"
+ "clearSearchTooltip": "Clear search field",
+ "location": "Location",
+ "created": "Created",
+ "edited": "Edited"
},
"space": {
"delete": "Delete",