feat: support pasting image from Slack (#5864)

This commit is contained in:
Lucas.Xu 2024-08-02 22:00:40 +08:00 committed by GitHub
parent 393850ae4b
commit 0abf916796
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 16 deletions

View File

@ -1,11 +1,10 @@
import 'dart:io';
import 'package:flutter/services.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/clipboard_service.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor_plugins/appflowy_editor_plugins.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
@ -246,10 +245,6 @@ void main() {
expect(editorState.document.root.children.length, 2);
final node = editorState.getNodeAtPath([0])!;
expect(node.type, ImageBlockKeys.type);
expect(
node.attributes[ImageBlockKeys.url],
'https://user-images.githubusercontent.com/9403740/262918875-603f4adb-58dd-49b5-8201-341d354935fd.png',
);
},
);
},

View File

@ -1,5 +1,3 @@
import 'package:flutter/material.dart';
import 'package:appflowy/plugins/document/application/document_bloc.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/clipboard_service.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/editor_state_paste_node_extension.dart';
@ -8,8 +6,10 @@ import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_p
import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/paste_from_in_app_json.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/paste_from_plain_text.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_backend/log.dart';
import 'package:appflowy_editor/appflowy_editor.dart' hide Log;
import 'package:appflowy_editor_plugins/appflowy_editor_plugins.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:string_validator/string_validator.dart';
@ -43,6 +43,7 @@ CommandShortcutEventHandler _pasteCommandHandler = (editorState) {
// paste as link preview
if (await _pasteAsLinkPreview(editorState, plainText)) {
Log.info('Pasted as link preview');
return;
}
@ -56,17 +57,14 @@ CommandShortcutEventHandler _pasteCommandHandler = (editorState) {
if (inAppJson != null && inAppJson.isNotEmpty) {
await editorState.deleteSelectionIfNeeded();
if (await editorState.pasteInAppJson(inAppJson)) {
Log.info('Pasted in app json');
return;
}
}
if (html != null && html.isNotEmpty) {
await editorState.deleteSelectionIfNeeded();
if (await editorState.pasteHtml(html)) {
return;
}
}
// if the image data is not null, we should handle it first
// because the image URL in the HTML may not be reachable due to permission issues
// For example, when pasting an image from Slack, the image URL provided is not public.
if (image != null && image.$2?.isNotEmpty == true) {
final documentBloc =
editorState.document.root.context?.read<DocumentBloc>();
@ -81,11 +79,21 @@ CommandShortcutEventHandler _pasteCommandHandler = (editorState) {
documentId,
);
if (result) {
Log.info('Pasted image');
return;
}
}
if (html != null && html.isNotEmpty) {
await editorState.deleteSelectionIfNeeded();
if (await editorState.pasteHtml(html)) {
Log.info('Pasted html');
return;
}
}
if (plainText != null && plainText.isNotEmpty) {
Log.info('Pasted plain text');
await editorState.pastePlainText(plainText);
}
}();