Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
fix: ai writer ux issues (#7640)
Richard Shiue07c767c4fadb
diff --git a/frontend/appflowy_flutter/lib/ai/widgets/prompt_input/desktop_prompt_text_field.dart b/frontend/appflowy_flutter/lib/ai/widgets/prompt_input/desktop_prompt_text_field.dartindex fcf487da94..97850f6a1c 100644--- a/frontend/appflowy_flutter/lib/ai/widgets/prompt_input/desktop_prompt_text_field.dart+++ b/frontend/appflowy_flutter/lib/ai/widgets/prompt_input/desktop_prompt_text_field.dart@@ -55,16 +55,18 @@ class _DesktopPromptInputState extends State<DesktopPromptInput> {super.initState();widget.textController.addListener(handleTextControllerChanged);- focusNode.addListener(- () {- if (!widget.hideDecoration) {- setState(() {}); // refresh border color- }- if (!focusNode.hasFocus) {- cancelMentionPage(); // hide menu when lost focus- }- },- );+ focusNode+ ..addListener(+ () {+ if (!widget.hideDecoration) {+ setState(() {}); // refresh border color+ }+ if (!focusNode.hasFocus) {+ cancelMentionPage(); // hide menu when lost focus+ }+ },+ )+ ..onKeyEvent = handleKeyEvent;updateSendButtonState();@@ -344,11 +346,16 @@ class _DesktopPromptInputState extends State<DesktopPromptInput> {}KeyEventResult handleKeyEvent(FocusNode node, KeyEvent event) {- if (event.character == '@') {- WidgetsBinding.instance.addPostFrameCallback((_) {- inputControlCubit.startSearching(widget.textController.value);- overlayController.show();- });+ // if (event.character == '@') {+ // WidgetsBinding.instance.addPostFrameCallback((_) {+ // inputControlCubit.startSearching(widget.textController.value);+ // overlayController.show();+ // });+ // }+ if (event is KeyDownEvent &&+ event.logicalKey == LogicalKeyboardKey.escape) {+ node.unfocus();+ return KeyEventResult.handled;}return KeyEventResult.ignored;}diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/ai/ai_writer_block_component.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/ai/ai_writer_block_component.dartindex 0f1e077d6d..769fabcd1f 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/ai/ai_writer_block_component.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/ai/ai_writer_block_component.dart@@ -98,6 +98,7 @@ class _AIWriterBlockComponentState extends State<AiWriterBlockComponent> {final textController = TextEditingController();final overlayController = OverlayPortalController();final layerLink = LayerLink();+ final focusNode = FocusNode();late final editorState = context.read<EditorState>();@@ -114,6 +115,7 @@ class _AIWriterBlockComponentState extends State<AiWriterBlockComponent> {@overridevoid dispose() {textController.dispose();+ focusNode.dispose();super.dispose();}@@ -145,10 +147,13 @@ class _AIWriterBlockComponentState extends State<AiWriterBlockComponent> {bottom: 16.0,),width: constraints.maxWidth,- child: OverlayContent(- editorState: editorState,- node: widget.node,- textController: textController,+ child: Focus(+ focusNode: focusNode,+ child: OverlayContent(+ editorState: editorState,+ node: widget.node,+ textController: textController,+ ),),),),diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/ai/widgets/ai_writer_prompt_input_more_button.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/ai/widgets/ai_writer_prompt_input_more_button.dartindex 75c6589326..72b8d9560b 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/ai/widgets/ai_writer_prompt_input_more_button.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/ai/widgets/ai_writer_prompt_input_more_button.dart@@ -135,9 +135,9 @@ class MoreAiWriterCommands extends StatelessWidget {return FlowyButton(leftIcon: FlowySvg(command.icon,- size: const Size.square(16),color: Theme.of(context).iconTheme.color,),+ leftIconSize: const Size.square(20),margin: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 6.0),text: FlowyText(command.i18n,diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/ai/widgets/ai_writer_scroll_wrapper.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/ai/widgets/ai_writer_scroll_wrapper.dartindex 326d1a44ab..90bce596a0 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/ai/widgets/ai_writer_scroll_wrapper.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/ai/widgets/ai_writer_scroll_wrapper.dart@@ -36,11 +36,9 @@ class _AiWriterScrollWrapperState extends State<AiWriterScrollWrapper> {onCreateNode: () {aiWriterRegistered = true;widget.editorState.service.keyboardService?.disableShortcuts();- HardwareKeyboard.instance.addHandler(cancelShortcutHandler);},onRemoveNode: () {aiWriterRegistered = false;- HardwareKeyboard.instance.removeHandler(cancelShortcutHandler);widget.editorState.service.keyboardService?.enableShortcuts();},onAppendToDocument: onAppendToDocument,@@ -48,6 +46,7 @@ class _AiWriterScrollWrapperState extends State<AiWriterScrollWrapper> {bool userHasScrolled = false;bool aiWriterRegistered = false;+ bool dialogShown = false;@overridevoid initState() {@@ -67,46 +66,51 @@ class _AiWriterScrollWrapperState extends State<AiWriterScrollWrapper> {value: aiWriterCubit,child: NotificationListener<ScrollNotification>(onNotification: handleScrollNotification,- child: MultiBlocListener(- listeners: [- BlocListener<AiWriterCubit, AiWriterState>(- listener: (context, state) {- if (state is DocumentContentEmptyAiWriterState) {- showConfirmDialog(- context: context,- title: LocaleKeys.ai_continueWritingEmptyDocumentTitle.tr(),- description: LocaleKeys- .ai_continueWritingEmptyDocumentDescription- .tr(),- onConfirm: state.onConfirm,- );- }- },- ),- BlocListener<AiWriterCubit, AiWriterState>(- listenWhen: (previous, current) =>- previous is GeneratingAiWriterState &&- current is ReadyAiWriterState,- listener: (context, state) {- widget.editorState.updateSelectionWithReason(null);+ child: Focus(+ autofocus: true,+ onKeyEvent: handleKeyEvent,+ child: MultiBlocListener(+ listeners: [+ BlocListener<AiWriterCubit, AiWriterState>(+ listener: (context, state) {+ if (state is DocumentContentEmptyAiWriterState) {+ showConfirmDialog(+ context: context,+ title:+ LocaleKeys.ai_continueWritingEmptyDocumentTitle.tr(),+ description: LocaleKeys+ .ai_continueWritingEmptyDocumentDescription+ .tr(),+ onConfirm: state.onConfirm,+ );+ }+ },+ ),+ BlocListener<AiWriterCubit, AiWriterState>(+ listenWhen: (previous, current) =>+ previous is GeneratingAiWriterState &&+ current is ReadyAiWriterState,+ listener: (context, state) {+ widget.editorState.updateSelectionWithReason(null);+ },+ ),+ ],+ child: OverlayPortal(+ controller: overlayController,+ overlayChildBuilder: (context) {+ return BlocBuilder<AiWriterCubit, AiWriterState>(+ builder: (context, state) {+ return AiWriterGestureDetector(+ behavior: state is RegisteredAiWriter+ ? HitTestBehavior.translucent+ : HitTestBehavior.deferToChild,+ onPointerEvent: () => onTapOutside(context),+ );+ },+ );},+ child: widget.child,),- ],- child: OverlayPortal(- controller: overlayController,- overlayChildBuilder: (context) {- return BlocBuilder<AiWriterCubit, AiWriterState>(- builder: (context, state) {- return AiWriterGestureDetector(- behavior: state is RegisteredAiWriter- ? HitTestBehavior.translucent- : HitTestBehavior.deferToChild,- onPointerEvent: () => onTapOutside(context),- );- },- );- },- child: widget.child,),),),@@ -153,9 +157,15 @@ class _AiWriterScrollWrapperState extends State<AiWriterScrollWrapper> {}}- bool cancelShortcutHandler(KeyEvent event) {- if (event is! KeyUpEvent) {- return false;+ KeyEventResult handleKeyEvent(FocusNode node, KeyEvent event) {+ if (!aiWriterRegistered) {+ return KeyEventResult.ignored;+ }+ if (dialogShown) {+ return KeyEventResult.handled;+ }+ if (event is! KeyDownEvent) {+ return KeyEventResult.ignored;}switch (event.logicalKey) {@@ -163,6 +173,7 @@ class _AiWriterScrollWrapperState extends State<AiWriterScrollWrapper> {if (aiWriterCubit.state case GeneratingAiWriterState _) {aiWriterCubit.stopStream();} else if (aiWriterCubit.hasUnusedResponse()) {+ dialogShown = true;showConfirmDialog(context: context,title: LocaleKeys.button_discard.tr(),@@ -171,23 +182,22 @@ class _AiWriterScrollWrapperState extends State<AiWriterScrollWrapper> {style: ConfirmPopupStyle.cancelAndOk,onConfirm: stopAndExit,onCancel: () {},- );+ ).then((_) => dialogShown = false);} else {stopAndExit();}- return true;+ return KeyEventResult.handled;case LogicalKeyboardKey.keyC- when HardwareKeyboard.instance.logicalKeysPressed- .contains(LogicalKeyboardKey.controlLeft):+ when HardwareKeyboard.instance.isControlPressed:if (aiWriterCubit.state case GeneratingAiWriterState _) {aiWriterCubit.stopStream();}- return true;+ return KeyEventResult.handled;default:break;}- return false;+ return KeyEventResult.ignored;}void onAppendToDocument() {diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/setting_ai_view/local_ai_setting.dart b/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/setting_ai_view/local_ai_setting.dartindex feec20afdb..57a72b6ca1 100644--- a/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/setting_ai_view/local_ai_setting.dart+++ b/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/setting_ai_view/local_ai_setting.dart@@ -84,7 +84,7 @@ class LocalAISettingHeader extends StatelessWidget {children: [Row(children: [- FlowyText(+ FlowyText.medium(LocaleKeys.settings_aiPage_keys_localAIToggleTitle.tr(),),const Spacer(),diff --git a/frontend/resources/translations/en.json b/frontend/resources/translations/en.jsonindex 429f1ea8c3..2b22da596c 100644--- a/frontend/resources/translations/en.json+++ b/frontend/resources/translations/en.json@@ -246,7 +246,7 @@"number": "Numbered list","table": "Table","blankDescription": "Format response",- "defaultDescription": "Auto mode",+ "defaultDescription": "Auto response format","textWithImageDescription": "@:chat.changeFormat.text with image","numberWithImageDescription": "@:chat.changeFormat.number with image","bulletWithImageDescription": "@:chat.changeFormat.bullet with image",