mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-04-24 14:47:13 -04:00
fix: some test erros
This commit is contained in:
parent
c5fe9fcc02
commit
1612b870c3
4 changed files with 38 additions and 8 deletions
|
@ -5,6 +5,7 @@ import 'package:appflowy/plugins/document/presentation/editor_plugins/block_menu
|
||||||
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/clipboard_service.dart';
|
||||||
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/custom_image_block_component/custom_image_block_component.dart';
|
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/custom_image_block_component/custom_image_block_component.dart';
|
||||||
import 'package:appflowy/plugins/document/presentation/editor_plugins/link_preview/custom_link_preview.dart';
|
import 'package:appflowy/plugins/document/presentation/editor_plugins/link_preview/custom_link_preview.dart';
|
||||||
|
import 'package:appflowy/plugins/document/presentation/editor_plugins/link_preview/paste_as/paste_as_menu.dart';
|
||||||
import 'package:appflowy/startup/startup.dart';
|
import 'package:appflowy/startup/startup.dart';
|
||||||
import 'package:appflowy_editor/appflowy_editor.dart';
|
import 'package:appflowy_editor/appflowy_editor.dart';
|
||||||
import 'package:appflowy_editor_plugins/appflowy_editor_plugins.dart';
|
import 'package:appflowy_editor_plugins/appflowy_editor_plugins.dart';
|
||||||
|
@ -320,6 +321,16 @@ void main() {
|
||||||
(tester) async {
|
(tester) async {
|
||||||
const url = 'https://appflowy.io';
|
const url = 'https://appflowy.io';
|
||||||
await tester.pasteContent(plainText: url, (editorState) async {
|
await tester.pasteContent(plainText: url, (editorState) async {
|
||||||
|
final pasteAsMenu = find.byType(PasteAsMenu);
|
||||||
|
expect(pasteAsMenu, findsOneWidget);
|
||||||
|
final bookmarkButton = find.descendant(
|
||||||
|
of: pasteAsMenu,
|
||||||
|
matching: find.text(
|
||||||
|
LocaleKeys.document_plugins_linkPreview_typeSelection_bookmark
|
||||||
|
.tr(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await tester.tapButton(bookmarkButton);
|
||||||
// the second one is the paragraph node
|
// the second one is the paragraph node
|
||||||
expect(editorState.document.root.children.length, 2);
|
expect(editorState.document.root.children.length, 2);
|
||||||
final node = editorState.getNodeAtPath([0])!;
|
final node = editorState.getNodeAtPath([0])!;
|
||||||
|
@ -363,6 +374,16 @@ void main() {
|
||||||
(tester) async {
|
(tester) async {
|
||||||
const url = 'https://appflowy.io';
|
const url = 'https://appflowy.io';
|
||||||
await tester.pasteContent(plainText: url, (editorState) async {
|
await tester.pasteContent(plainText: url, (editorState) async {
|
||||||
|
final pasteAsMenu = find.byType(PasteAsMenu);
|
||||||
|
expect(pasteAsMenu, findsOneWidget);
|
||||||
|
final bookmarkButton = find.descendant(
|
||||||
|
of: pasteAsMenu,
|
||||||
|
matching: find.text(
|
||||||
|
LocaleKeys.document_plugins_linkPreview_typeSelection_bookmark
|
||||||
|
.tr(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await tester.tapButton(bookmarkButton);
|
||||||
// the second one is the paragraph node
|
// the second one is the paragraph node
|
||||||
expect(editorState.document.root.children.length, 2);
|
expect(editorState.document.root.children.length, 2);
|
||||||
final node = editorState.getNodeAtPath([0])!;
|
final node = editorState.getNodeAtPath([0])!;
|
||||||
|
|
|
@ -163,7 +163,7 @@ Future<bool> _pasteAsLinkPreview(
|
||||||
EditorState editorState,
|
EditorState editorState,
|
||||||
String? text,
|
String? text,
|
||||||
) async {
|
) async {
|
||||||
if (!UniversalPlatform.isMobile) return false;
|
final isMobile = UniversalPlatform.isMobile;
|
||||||
// the url should contain a protocol
|
// the url should contain a protocol
|
||||||
if (text == null || !isURL(text, {'require_protocol': true})) {
|
if (text == null || !isURL(text, {'require_protocol': true})) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -195,6 +195,8 @@ Future<bool> _pasteAsLinkPreview(
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isMobile && !isImageUrl) return false;
|
||||||
|
|
||||||
// insert the text with link format
|
// insert the text with link format
|
||||||
final textTransaction = editorState.transaction
|
final textTransaction = editorState.transaction
|
||||||
..insertText(
|
..insertText(
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/paste_from_plain_text.dart';
|
||||||
import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';
|
import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';
|
||||||
import 'package:appflowy/shared/markdown_to_document.dart';
|
import 'package:appflowy/shared/markdown_to_document.dart';
|
||||||
import 'package:appflowy/shared/patterns/common_patterns.dart';
|
import 'package:appflowy/shared/patterns/common_patterns.dart';
|
||||||
|
@ -13,6 +14,7 @@ extension PasteFromHtml on EditorState {
|
||||||
}
|
}
|
||||||
if (nodes.length == 1) {
|
if (nodes.length == 1) {
|
||||||
await pasteSingleLineNode(nodes.first);
|
await pasteSingleLineNode(nodes.first);
|
||||||
|
checkToShowPasteAsMenu(nodes.first);
|
||||||
} else {
|
} else {
|
||||||
await pasteMultiLineNodes(nodes.toList());
|
await pasteMultiLineNodes(nodes.toList());
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,13 +43,7 @@ extension PasteFromPlainText on EditorState {
|
||||||
}
|
}
|
||||||
if (nodes.length == 1) {
|
if (nodes.length == 1) {
|
||||||
await pasteSingleLineNode(nodes.first);
|
await pasteSingleLineNode(nodes.first);
|
||||||
final href = _getLinkFromNode(nodes.first);
|
checkToShowPasteAsMenu(nodes.first);
|
||||||
if (href != null && !UniversalPlatform.isMobile) {
|
|
||||||
final context = document.root.context;
|
|
||||||
if (context != null && context.mounted) {
|
|
||||||
PasteAsMenuService(context: context, editorState: this).show(href);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
await pasteMultiLineNodes(nodes.toList());
|
await pasteMultiLineNodes(nodes.toList());
|
||||||
}
|
}
|
||||||
|
@ -74,9 +68,20 @@ extension PasteFromPlainText on EditorState {
|
||||||
AppFlowyRichTextKeys.href: plainText,
|
AppFlowyRichTextKeys.href: plainText,
|
||||||
});
|
});
|
||||||
await apply(transaction);
|
await apply(transaction);
|
||||||
|
checkToShowPasteAsMenu(node);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void checkToShowPasteAsMenu(Node node) {
|
||||||
|
final href = _getLinkFromNode(node);
|
||||||
|
if (href != null && !UniversalPlatform.isMobile) {
|
||||||
|
final context = document.root.context;
|
||||||
|
if (context != null && context.mounted) {
|
||||||
|
PasteAsMenuService(context: context, editorState: this).show(href);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
String? _getLinkFromNode(Node node) {
|
String? _getLinkFromNode(Node node) {
|
||||||
for (final insert in node.delta!) {
|
for (final insert in node.delta!) {
|
||||||
final link = insert.attributes?.href;
|
final link = insert.attributes?.href;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue