Feature/smart edit v2 (#1880)

* feat: add edit api to openai client

* feat: add translation

* chore: format code

* feat: add smart edit plugin

* fix: close http.client when dispose

* fix: insert openai result to wrong position

* feat: optimize the replace text logic

* test: add test for normalize and getTextInSelection function

* chore: update error message
This commit is contained in:
Lucas.Xu 2023-02-28 14:34:13 +08:00 committed by GitHub
parent 1945b0fe05
commit 085ef8f668
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 701 additions and 44 deletions

View file

@ -4,6 +4,8 @@ import 'package:appflowy/plugins/document/presentation/plugins/grid/grid_menu_it
import 'package:appflowy/plugins/document/presentation/plugins/grid/grid_node_widget.dart';
import 'package:appflowy/plugins/document/presentation/plugins/openai/widgets/auto_completion_node_widget.dart';
import 'package:appflowy/plugins/document/presentation/plugins/openai/widgets/auto_completion_plugins.dart';
import 'package:appflowy/plugins/document/presentation/plugins/openai/widgets/smart_edit_node_widget.dart';
import 'package:appflowy/plugins/document/presentation/plugins/openai/widgets/smart_edit_toolbar_item.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor_plugins/appflowy_editor_plugins.dart';
@ -142,6 +144,8 @@ class _AppFlowyEditorPageState extends State<_AppFlowyEditorPage> {
kCalloutType: CalloutNodeWidgetBuilder(),
// Auto Generator,
kAutoCompletionInputType: AutoCompletionInputBuilder(),
// Smart Edit,
kSmartEditType: SmartEditInputBuilder(),
},
shortcutEvents: [
// Divider
@ -172,6 +176,9 @@ class _AppFlowyEditorPageState extends State<_AppFlowyEditorPage> {
autoGeneratorMenuItem,
]
],
toolbarItems: [
smartEditItem,
],
themeData: theme.copyWith(extensions: [
...theme.extensions.values,
customEditorTheme(context),
@ -203,6 +210,7 @@ class _AppFlowyEditorPageState extends State<_AppFlowyEditorPage> {
}
final temporaryNodeTypes = [
kAutoCompletionInputType,
kSmartEditType,
];
final iterator = NodeIterator(
document: document,