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.

fix: stop generating in ai chat and writer (#7534)

Richard Shiue36bf90e81bb2
diff --git a/frontend/appflowy_flutter/lib/ai/widgets/prompt_input/send_button.dart b/frontend/appflowy_flutter/lib/ai/widgets/prompt_input/send_button.dart
index 20def4ca5e..cca6e65f63 100644
--- a/frontend/appflowy_flutter/lib/ai/widgets/prompt_input/send_button.dart
+++ b/frontend/appflowy_flutter/lib/ai/widgets/prompt_input/send_button.dart
@@ -1,4 +1,6 @@
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/flowy_infra_ui.dart';
import 'package:flutter/material.dart';
import 'package:universal_platform/universal_platform.dart';
@@ -23,6 +25,23 @@ class PromptInputSendButton extends StatelessWidget {
Widget build(BuildContext context) {
return FlowyIconButton(
width: _buttonSize,
+ richTooltipText: switch (state) {
+ SendButtonState.streaming => TextSpan(
+ children: [
+ TextSpan(
+ text: '${LocaleKeys.chat_stopTooltip.tr()} ',
+ style: context.tooltipTextStyle(),
+ ),
+ TextSpan(
+ text: 'ESC',
+ style: context
+ .tooltipTextStyle()
+ ?.copyWith(color: Theme.of(context).hintColor),
+ ),
+ ],
+ ),
+ _ => null,
+ },
icon: switch (state) {
SendButtonState.enabled => FlowySvg(
FlowySvgs.ai_send_filled_s,
diff --git a/frontend/appflowy_flutter/lib/plugins/ai_chat/chat_page.dart b/frontend/appflowy_flutter/lib/plugins/ai_chat/chat_page.dart
index 2d0c05b2c4..5400297870 100644
--- a/frontend/appflowy_flutter/lib/plugins/ai_chat/chat_page.dart
+++ b/frontend/appflowy_flutter/lib/plugins/ai_chat/chat_page.dart
@@ -93,14 +93,24 @@ class AIChatPage extends StatelessWidget {
}
}
},
- child: CallbackShortcuts(
- bindings: {
- SingleActivator(LogicalKeyboardKey.escape): () {
- context.read<ChatBloc>().add(ChatEvent.stopStream());
- },
- SingleActivator(control: true, LogicalKeyboardKey.keyC): () {
- context.read<ChatBloc>().add(ChatEvent.stopStream());
- },
+ child: FocusScope(
+ onKeyEvent: (focusNode, event) {
+ if (event is! KeyUpEvent) {
+ return KeyEventResult.ignored;
+ }
+
+ if (event.logicalKey == LogicalKeyboardKey.escape ||
+ event.logicalKey == LogicalKeyboardKey.keyC &&
+ HardwareKeyboard.instance.isControlPressed) {
+ final chatBloc = context.read<ChatBloc>();
+ if (chatBloc.state.promptResponseState !=
+ PromptResponseState.ready) {
+ chatBloc.add(ChatEvent.stopStream());
+ return KeyEventResult.handled;
+ }
+ }
+
+ return KeyEventResult.ignored;
},
child: _ChatContentPage(
view: view,
diff --git a/frontend/resources/translations/en.json b/frontend/resources/translations/en.json
index 80798e1ff6..42dbb89155 100644
--- a/frontend/resources/translations/en.json
+++ b/frontend/resources/translations/en.json
@@ -256,7 +256,9 @@
"selectMessages": "Select messages",
"nSelected": "{} selected",
"allSelected": "All selected"
- }
+ },
+ "stopTooltip": "Stop generating"
+
},
"trash": {
"text": "Trash",