fix: copy link to block not supported well

This commit is contained in:
Morn 2025-04-12 13:38:38 +08:00
parent e710fc1d5c
commit 8a892cc1cd
2 changed files with 7 additions and 10 deletions

View file

@ -483,16 +483,6 @@ void main() {
}); });
}); });
testWidgets('paste image url without extension', (tester) async {
const plainText =
'https://images.unsplash.com/photo-1469474968028-56623f02e42e?ixlib=rb-4.0.3&q=85&fm=jpg&crop=entropy&cs=srgb&dl=david-marcu-78A265wPiO4-unsplash.jpg&w=640';
await tester.pasteContent(plainText: plainText, (editorState) {
final node = editorState.getNodeAtPath([0])!;
expect(node.type, ImageBlockKeys.type);
expect(node.attributes[ImageBlockKeys.url], isNotEmpty);
});
});
const testMarkdownText = ''' const testMarkdownText = '''
# I'm h1 # I'm h1
## I'm h2 ## I'm h2

View file

@ -1,3 +1,4 @@
import 'package:appflowy/plugins/document/presentation/editor_plugins/link_preview/custom_link_parser.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/mention/mention_block.dart'; import 'package:appflowy/plugins/document/presentation/editor_plugins/mention/mention_block.dart';
import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:appflowy_editor/appflowy_editor.dart';
@ -27,9 +28,15 @@ extension TextDeltaExtension on Delta {
if (op.text == MentionBlockKeys.mentionChar) { if (op.text == MentionBlockKeys.mentionChar) {
final mention = attributes?[MentionBlockKeys.mention]; final mention = attributes?[MentionBlockKeys.mention];
final mentionPageId = mention?[MentionBlockKeys.pageId]; final mentionPageId = mention?[MentionBlockKeys.pageId];
final mentionType = mention?[MentionBlockKeys.type];
if (mentionPageId != null) { if (mentionPageId != null) {
text += await getMentionPageName(mentionPageId); text += await getMentionPageName(mentionPageId);
continue; continue;
} else if (mentionType == MentionType.externalLink.name) {
final url = mention?[MentionBlockKeys.url] ?? '';
final info = await LinkInfoCache().get(url);
text += info?.siteName ?? url;
continue;
} }
} }