Skip to content

Commit 4997ac9

Browse files
asjqkkkkLucasXu0
andauthored
feat: revamp link preivew (#7692)
* feat: revamp link preivew * feat: add convert to menu for link hover menu * feat: add mention link * feat: support convert preview to mention * feat: add embed link preview * fix: some test erros * fix: test errors * fix: some UI issues * chore: add test for url * chore: add test for mention * chore: add test for bookmark * chore: add test for embed * chore: remove unuse import * fix: some UI issues * fix: remove text span overlay on mobile * fix: code lint error --------- Co-authored-by: Lucas <[email protected]>
1 parent e3bbabd commit 4997ac9

38 files changed

+3564
-167
lines changed

frontend/appflowy_flutter/integration_test/desktop/document/document_copy_and_paste_test.dart

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import 'dart:async';
12
import 'dart:io';
23

34
import 'package:appflowy/generated/locale_keys.g.dart';
4-
import 'package:appflowy/plugins/document/presentation/editor_plugins/block_menu/block_menu_button.dart';
55
import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/clipboard_service.dart';
66
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/custom_image_block_component/custom_image_block_component.dart';
77
import 'package:appflowy/plugins/document/presentation/editor_plugins/link_preview/custom_link_preview.dart';
8+
import 'package:appflowy/plugins/document/presentation/editor_plugins/link_preview/link_preview_menu.dart';
9+
import 'package:appflowy/plugins/document/presentation/editor_plugins/link_preview/paste_as/paste_as_menu.dart';
810
import 'package:appflowy/startup/startup.dart';
911
import 'package:appflowy_editor/appflowy_editor.dart';
1012
import 'package:appflowy_editor_plugins/appflowy_editor_plugins.dart';
@@ -320,8 +322,14 @@ void main() {
320322
(tester) async {
321323
const url = 'https://appflowy.io';
322324
await tester.pasteContent(plainText: url, (editorState) async {
325+
final pasteAsMenu = find.byType(PasteAsMenu);
326+
expect(pasteAsMenu, findsOneWidget);
327+
final bookmarkButton = find.text(
328+
LocaleKeys.document_plugins_linkPreview_typeSelection_bookmark.tr(),
329+
);
330+
await tester.tapButton(bookmarkButton);
323331
// the second one is the paragraph node
324-
expect(editorState.document.root.children.length, 2);
332+
expect(editorState.document.root.children.length, 1);
325333
final node = editorState.getNodeAtPath([0])!;
326334
expect(node.type, LinkPreviewBlockKeys.type);
327335
expect(node.attributes[LinkPreviewBlockKeys.url], url);
@@ -333,19 +341,19 @@ void main() {
333341
await tester.hoverOnWidget(
334342
find.byType(CustomLinkPreviewWidget),
335343
onHover: () async {
336-
final convertToLinkButton = find.byWidgetPredicate((widget) {
337-
return widget is MenuBlockButton &&
338-
widget.tooltip ==
339-
LocaleKeys.document_plugins_urlPreview_convertToLink.tr();
340-
});
344+
/// show menu
345+
final menu = find.byType(CustomLinkPreviewMenu);
346+
expect(menu, findsOneWidget);
347+
await tester.tapButton(menu);
348+
349+
final convertToLinkButton = find.text(
350+
LocaleKeys.document_plugins_linkPreview_linkPreviewMenu_toUrl.tr(),
351+
);
341352
expect(convertToLinkButton, findsOneWidget);
342-
await tester.tap(convertToLinkButton);
343-
await tester.pumpAndSettle();
353+
await tester.tapButton(convertToLinkButton);
344354
},
345355
);
346356

347-
await tester.pumpAndSettle();
348-
349357
final editorState = tester.editor.getCurrentEditorState();
350358
final textNode = editorState.getNodeAtPath([0])!;
351359
expect(textNode.type, ParagraphBlockKeys.type);
@@ -363,14 +371,20 @@ void main() {
363371
(tester) async {
364372
const url = 'https://appflowy.io';
365373
await tester.pasteContent(plainText: url, (editorState) async {
374+
final pasteAsMenu = find.byType(PasteAsMenu);
375+
expect(pasteAsMenu, findsOneWidget);
376+
final bookmarkButton = find.text(
377+
LocaleKeys.document_plugins_linkPreview_typeSelection_bookmark.tr(),
378+
);
379+
await tester.tapButton(bookmarkButton);
366380
// the second one is the paragraph node
367-
expect(editorState.document.root.children.length, 2);
381+
expect(editorState.document.root.children.length, 1);
368382
final node = editorState.getNodeAtPath([0])!;
369383
expect(node.type, LinkPreviewBlockKeys.type);
370384
expect(node.attributes[LinkPreviewBlockKeys.url], url);
371385
});
372386

373-
await tester.editor.tapLineOfEditorAt(0);
387+
374388
await tester.simulateKeyEvent(
375389
LogicalKeyboardKey.keyZ,
376390
isControlPressed:
@@ -521,7 +535,7 @@ void main() {
521535

522536
extension on WidgetTester {
523537
Future<void> pasteContent(
524-
void Function(EditorState editorState) test, {
538+
FutureOr<void> Function(EditorState editorState) test, {
525539
Future<void> Function(EditorState editorState)? beforeTest,
526540
String? plainText,
527541
String? html,
@@ -558,6 +572,6 @@ extension on WidgetTester {
558572
);
559573
await pumpAndSettle(const Duration(milliseconds: 1000));
560574

561-
test(editor.getCurrentEditorState());
575+
await test(editor.getCurrentEditorState());
562576
}
563577
}

0 commit comments

Comments
 (0)