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.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
feat: support pasting image from Slack (#5864)
Lucas.Xu0abf916796c5
diff --git a/frontend/appflowy_flutter/integration_test/desktop/document/document_copy_and_paste_test.dart b/frontend/appflowy_flutter/integration_test/desktop/document/document_copy_and_paste_test.dartindex 730d776460..9fe8d37070 100644--- a/frontend/appflowy_flutter/integration_test/desktop/document/document_copy_and_paste_test.dart+++ b/frontend/appflowy_flutter/integration_test/desktop/document/document_copy_and_paste_test.dart@@ -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',- );},);},diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/copy_and_paste/custom_paste_command.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/copy_and_paste/custom_paste_command.dartindex 53812fbfe4..e81cf2f325 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/copy_and_paste/custom_paste_command.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/copy_and_paste/custom_paste_command.dart@@ -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_pimport '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 previewif (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);}}();