diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/copy_and_paste/paste_from_plain_text.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/copy_and_paste/paste_from_plain_text.dart index 0b51f7361c..fcb12cefa5 100644 --- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/copy_and_paste/paste_from_plain_text.dart +++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/copy_and_paste/paste_from_plain_text.dart @@ -73,8 +73,10 @@ extension PasteFromPlainText on EditorState { } void checkToShowPasteAsMenu(Node node) { + if (selection == null || !selection!.isCollapsed) return; + if (UniversalPlatform.isMobile) return; final href = _getLinkFromNode(node); - if (href != null && !UniversalPlatform.isMobile) { + if (href != null) { final context = document.root.context; if (context != null && context.mounted) { PasteAsMenuService(context: context, editorState: this).show(href); diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_embed/link_embed_block_component.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_embed/link_embed_block_component.dart index f2111a9576..cef8044fc4 100644 --- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_embed/link_embed_block_component.dart +++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_embed/link_embed_block_component.dart @@ -64,10 +64,10 @@ class LinkEmbedBlockComponentState extends State parser.addLinkInfoListener((v) { if (mounted) { setState(() { - linkInfo = v; - if (v.isEmpty()) { + if (v.isEmpty() && linkInfo.isEmpty()) { status = EmbedLoadingStatus.error; } else { + linkInfo = v; status = EmbedLoadingStatus.idle; } }); @@ -197,27 +197,29 @@ class LinkEmbedBlockComponentState extends State ), ), HSpace(12), - Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisSize: MainAxisSize.min, - children: [ - FlowyText( - linkInfo.siteName ?? '', - color: textScheme.primary, - fontSize: 14, - figmaLineHeight: 20, - fontWeight: FontWeight.w600, - overflow: TextOverflow.ellipsis, - ), - VSpace(4), - FlowyText.regular( - url, - color: textScheme.secondary, - fontSize: 12, - figmaLineHeight: 16, - overflow: TextOverflow.ellipsis, - ), - ], + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + FlowyText( + linkInfo.siteName ?? '', + color: textScheme.primary, + fontSize: 14, + figmaLineHeight: 20, + fontWeight: FontWeight.w600, + overflow: TextOverflow.ellipsis, + ), + VSpace(4), + FlowyText.regular( + url, + color: textScheme.secondary, + fontSize: 12, + figmaLineHeight: 16, + overflow: TextOverflow.ellipsis, + ), + ], + ), ), ], ), diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_preview/custom_link_parser.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_preview/custom_link_parser.dart index 15794ee176..27a16965ec 100644 --- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_preview/custom_link_parser.dart +++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_preview/custom_link_parser.dart @@ -32,11 +32,12 @@ class LinkParser { imageUrl: previewData.image?.url, faviconUrl: favicon?.url, ); - await _cache.set(url, linkInfo); + if (!linkInfo.isEmpty()) await _cache.set(url, linkInfo); refreshLinkInfo(linkInfo); return linkInfo; } catch (e, s) { Log.error('get link info error: ', e, s); + refreshLinkInfo(LinkInfo()); return null; } } @@ -99,6 +100,7 @@ class LinkInfo { return FlowyNetworkSvg( iconUrl, height: size.height, + width: size.width, errorWidget: const FlowySvg(FlowySvgs.toolbar_link_earth_m), ); } @@ -106,6 +108,7 @@ class LinkInfo { url: iconUrl, fit: BoxFit.contain, height: size.height, + width: size.width, errorWidgetBuilder: (context, error, stackTrace) => const FlowySvg(FlowySvgs.toolbar_link_earth_m), ); diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/mention_link_block.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/mention_link_block.dart index 0241137821..7a807fef64 100644 --- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/mention_link_block.dart +++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/mention_link_block.dart @@ -43,7 +43,7 @@ class _MentionLinkBlockState extends State { final parser = LinkParser(); _LoadingStatus status = _LoadingStatus.loading; final previewController = PopoverController(); - LinkInfo? linkInfo; + LinkInfo linkInfo = LinkInfo(); bool isHovering = false; int previewFocusNum = 0; bool isPreviewHovering = false; @@ -60,7 +60,7 @@ class _MentionLinkBlockState extends State { int get index => widget.index; bool get readyForPreview => - status == _LoadingStatus.idle && !(linkInfo?.isEmpty() ?? true); + status == _LoadingStatus.idle && !linkInfo.isEmpty(); @override void initState() { @@ -69,10 +69,10 @@ class _MentionLinkBlockState extends State { parser.addLinkInfoListener((v) { if (mounted) { setState(() { - linkInfo = v; - if (v.isEmpty()) { + if (v.isEmpty() && linkInfo.isEmpty()) { status = _LoadingStatus.error; } else { + linkInfo = v; status = _LoadingStatus.idle; } }); @@ -112,7 +112,7 @@ class _MentionLinkBlockState extends State { borderRadius: BorderRadius.circular(16), popupBuilder: (context) => readyForPreview ? MentionLinkPreview( - linkInfo: linkInfo ?? LinkInfo(), + linkInfo: linkInfo, showAtBottom: showAtBottom, triggerSize: getSizeFromKey(), onEnter: (e) { @@ -170,7 +170,7 @@ class _MentionLinkBlockState extends State { HSpace(4), Flexible( child: FlowyText( - linkInfo?.siteName ?? url, + linkInfo.siteName ?? url, color: theme.textColorScheme.primary, fontSize: 14, figmaLineHeight: 20, @@ -194,7 +194,7 @@ class _MentionLinkBlockState extends State { child: const CircularProgressIndicator(strokeWidth: 1), ); } else { - icon = linkInfo?.buildIconWidget() ?? defaultWidget; + icon = linkInfo.buildIconWidget(); } return SizedBox( height: 20,