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: show cursor at end of selection when generating (#7655)

Richard Shiue3c99105b23ba
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.dart
index 90bce596a0..6b5f27e028 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
@@ -208,11 +208,26 @@ class _AiWriterScrollWrapperState extends State<AiWriterScrollWrapper> {
throttler.call(() {
if (aiWriterCubit.aiWriterNode != null) {
final path = aiWriterCubit.aiWriterNode!.path;
- if (path.isNotEmpty) {
- widget.editorState.updateSelectionWithReason(
- Selection.collapsed(Position(path: path)),
- );
+
+ if (path.isEmpty) {
+ return;
}
+
+ if (path.previous.isNotEmpty) {
+ final node = widget.editorState.getNodeAtPath(path.previous);
+ if (node != null && node.delta != null && node.delta!.isNotEmpty) {
+ widget.editorState.updateSelectionWithReason(
+ Selection.collapsed(
+ Position(path: path, offset: node.delta!.length),
+ ),
+ );
+ return;
+ }
+ }
+
+ widget.editorState.updateSelectionWithReason(
+ Selection.collapsed(Position(path: path)),
+ );
}
});
}