mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: optimize the open ai input status and clear the auto completion… (#1865)
* feat: optimize the open ai input status and clear the auto completion node when exiting the doc * fix: import error on appflowy editor
This commit is contained in:
parent
3fd4371d2c
commit
346a09b2ae
@ -33,7 +33,6 @@ class DocumentPage extends StatefulWidget {
|
||||
|
||||
class _DocumentPageState extends State<DocumentPage> {
|
||||
late DocumentBloc documentBloc;
|
||||
final FocusNode _focusNode = FocusNode();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@ -44,6 +43,15 @@ class _DocumentPageState extends State<DocumentPage> {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> dispose() async {
|
||||
// https://github.com/flutter/flutter/issues/64935#issuecomment-686852369
|
||||
super.dispose();
|
||||
|
||||
await _clearTemporaryNodes();
|
||||
await documentBloc.close();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MultiBlocProvider(
|
||||
@ -72,13 +80,6 @@ class _DocumentPageState extends State<DocumentPage> {
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> dispose() async {
|
||||
documentBloc.close();
|
||||
_focusNode.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Widget _renderDocument(BuildContext context, DocumentState state) {
|
||||
return Column(
|
||||
children: [
|
||||
@ -172,4 +173,29 @@ class _DocumentPageState extends State<DocumentPage> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _clearTemporaryNodes() async {
|
||||
final editorState = documentBloc.editorState;
|
||||
final document = editorState.document;
|
||||
if (document.root.children.isEmpty) {
|
||||
return;
|
||||
}
|
||||
final temporaryNodeTypes = [
|
||||
kAutoCompletionInputType,
|
||||
];
|
||||
final iterator = NodeIterator(
|
||||
document: document,
|
||||
startNode: document.root.children.first,
|
||||
);
|
||||
final transaction = editorState.transaction;
|
||||
while (iterator.moveNext()) {
|
||||
final node = iterator.current;
|
||||
if (temporaryNodeTypes.contains(node.type)) {
|
||||
transaction.deleteNode(node);
|
||||
}
|
||||
}
|
||||
if (transaction.operations.isNotEmpty) {
|
||||
await editorState.apply(transaction, withUpdateCursor: false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,10 @@ extension TextRobot on EditorState {
|
||||
}) async {
|
||||
final lines = text.split('\n');
|
||||
for (final line in lines) {
|
||||
if (line.isEmpty) continue;
|
||||
if (line.isEmpty) {
|
||||
await insertNewLineAtCurrentSelection();
|
||||
continue;
|
||||
}
|
||||
switch (inputType) {
|
||||
case TextRobotInputType.character:
|
||||
final iterator = line.runes.iterator;
|
||||
@ -34,11 +37,6 @@ extension TextRobot on EditorState {
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// insert new line
|
||||
if (lines.length > 1) {
|
||||
await insertNewLineAtCurrentSelection();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -257,9 +257,14 @@ class _AutoCompletionInputState extends State<_AutoCompletionInput> {
|
||||
}, (textCompletion) async {
|
||||
loading.stop();
|
||||
await _makeSurePreviousNodeIsEmptyTextNode();
|
||||
await widget.editorState.autoInsertText(
|
||||
textCompletion.choices.first.text,
|
||||
);
|
||||
// Open AI result uses two '\n' as the begin syntax.
|
||||
var texts = textCompletion.choices.first.text.split('\n');
|
||||
if (texts.length > 2) {
|
||||
texts.removeRange(0, 2);
|
||||
await widget.editorState.autoInsertText(
|
||||
texts.join('\n'),
|
||||
);
|
||||
}
|
||||
focusNode.requestFocus();
|
||||
});
|
||||
}, (error) async {
|
||||
|
@ -315,7 +315,7 @@ Section 1.10.32 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC
|
||||
var jsonString = '';
|
||||
switch (fileType) {
|
||||
case ExportFileType.json:
|
||||
jsonString = jsonEncode(plainText);
|
||||
jsonString = plainText;
|
||||
break;
|
||||
case ExportFileType.markdown:
|
||||
jsonString = jsonEncode(markdownToDocument(plainText).toJson());
|
||||
|
@ -2,11 +2,13 @@ PODS:
|
||||
- flowy_infra_ui (0.0.1):
|
||||
- FlutterMacOS
|
||||
- FlutterMacOS (1.0.0)
|
||||
- path_provider_macos (0.0.1):
|
||||
- path_provider_foundation (0.0.1):
|
||||
- Flutter
|
||||
- FlutterMacOS
|
||||
- rich_clipboard_macos (0.0.1):
|
||||
- FlutterMacOS
|
||||
- shared_preferences_macos (0.0.1):
|
||||
- shared_preferences_foundation (0.0.1):
|
||||
- Flutter
|
||||
- FlutterMacOS
|
||||
- url_launcher_macos (0.0.1):
|
||||
- FlutterMacOS
|
||||
@ -14,9 +16,9 @@ PODS:
|
||||
DEPENDENCIES:
|
||||
- flowy_infra_ui (from `Flutter/ephemeral/.symlinks/plugins/flowy_infra_ui/macos`)
|
||||
- FlutterMacOS (from `Flutter/ephemeral`)
|
||||
- path_provider_macos (from `Flutter/ephemeral/.symlinks/plugins/path_provider_macos/macos`)
|
||||
- path_provider_foundation (from `Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/macos`)
|
||||
- rich_clipboard_macos (from `Flutter/ephemeral/.symlinks/plugins/rich_clipboard_macos/macos`)
|
||||
- shared_preferences_macos (from `Flutter/ephemeral/.symlinks/plugins/shared_preferences_macos/macos`)
|
||||
- shared_preferences_foundation (from `Flutter/ephemeral/.symlinks/plugins/shared_preferences_foundation/macos`)
|
||||
- url_launcher_macos (from `Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos`)
|
||||
|
||||
EXTERNAL SOURCES:
|
||||
@ -24,22 +26,22 @@ EXTERNAL SOURCES:
|
||||
:path: Flutter/ephemeral/.symlinks/plugins/flowy_infra_ui/macos
|
||||
FlutterMacOS:
|
||||
:path: Flutter/ephemeral
|
||||
path_provider_macos:
|
||||
:path: Flutter/ephemeral/.symlinks/plugins/path_provider_macos/macos
|
||||
path_provider_foundation:
|
||||
:path: Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/macos
|
||||
rich_clipboard_macos:
|
||||
:path: Flutter/ephemeral/.symlinks/plugins/rich_clipboard_macos/macos
|
||||
shared_preferences_macos:
|
||||
:path: Flutter/ephemeral/.symlinks/plugins/shared_preferences_macos/macos
|
||||
shared_preferences_foundation:
|
||||
:path: Flutter/ephemeral/.symlinks/plugins/shared_preferences_foundation/macos
|
||||
url_launcher_macos:
|
||||
:path: Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos
|
||||
|
||||
SPEC CHECKSUMS:
|
||||
flowy_infra_ui: c34d49d615ed9fe552cd47f90d7850815a74e9e9
|
||||
FlutterMacOS: ae6af50a8ea7d6103d888583d46bd8328a7e9811
|
||||
path_provider_macos: 3c0c3b4b0d4a76d2bf989a913c2de869c5641a19
|
||||
path_provider_foundation: 37748e03f12783f9de2cb2c4eadfaa25fe6d4852
|
||||
rich_clipboard_macos: 43364b66b9dc69d203eb8dd6d758e2d12e02723c
|
||||
shared_preferences_macos: a64dc611287ed6cbe28fd1297898db1336975727
|
||||
url_launcher_macos: 597e05b8e514239626bcf4a850fcf9ef5c856ec3
|
||||
shared_preferences_foundation: 297b3ebca31b34ec92be11acd7fb0ba932c822ca
|
||||
url_launcher_macos: c04e4fa86382d4f94f6b38f14625708be3ae52e2
|
||||
|
||||
PODFILE CHECKSUM: 6eac6b3292e5142cfc23bdeb71848a40ec51c14c
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user