fix: some UI issues

This commit is contained in:
Morn 2025-04-10 09:59:12 +08:00
parent add9f16717
commit 05b0160b80
4 changed files with 39 additions and 32 deletions

View file

@ -73,8 +73,10 @@ extension PasteFromPlainText on EditorState {
} }
void checkToShowPasteAsMenu(Node node) { void checkToShowPasteAsMenu(Node node) {
if (selection == null || !selection!.isCollapsed) return;
if (UniversalPlatform.isMobile) return;
final href = _getLinkFromNode(node); final href = _getLinkFromNode(node);
if (href != null && !UniversalPlatform.isMobile) { if (href != null) {
final context = document.root.context; final context = document.root.context;
if (context != null && context.mounted) { if (context != null && context.mounted) {
PasteAsMenuService(context: context, editorState: this).show(href); PasteAsMenuService(context: context, editorState: this).show(href);

View file

@ -64,10 +64,10 @@ class LinkEmbedBlockComponentState extends State<LinkEmbedBlockComponent>
parser.addLinkInfoListener((v) { parser.addLinkInfoListener((v) {
if (mounted) { if (mounted) {
setState(() { setState(() {
linkInfo = v; if (v.isEmpty() && linkInfo.isEmpty()) {
if (v.isEmpty()) {
status = EmbedLoadingStatus.error; status = EmbedLoadingStatus.error;
} else { } else {
linkInfo = v;
status = EmbedLoadingStatus.idle; status = EmbedLoadingStatus.idle;
} }
}); });
@ -197,7 +197,8 @@ class LinkEmbedBlockComponentState extends State<LinkEmbedBlockComponent>
), ),
), ),
HSpace(12), HSpace(12),
Column( Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
@ -219,6 +220,7 @@ class LinkEmbedBlockComponentState extends State<LinkEmbedBlockComponent>
), ),
], ],
), ),
),
], ],
), ),
), ),

View file

@ -32,11 +32,12 @@ class LinkParser {
imageUrl: previewData.image?.url, imageUrl: previewData.image?.url,
faviconUrl: favicon?.url, faviconUrl: favicon?.url,
); );
await _cache.set(url, linkInfo); if (!linkInfo.isEmpty()) await _cache.set(url, linkInfo);
refreshLinkInfo(linkInfo); refreshLinkInfo(linkInfo);
return linkInfo; return linkInfo;
} catch (e, s) { } catch (e, s) {
Log.error('get link info error: ', e, s); Log.error('get link info error: ', e, s);
refreshLinkInfo(LinkInfo());
return null; return null;
} }
} }
@ -99,6 +100,7 @@ class LinkInfo {
return FlowyNetworkSvg( return FlowyNetworkSvg(
iconUrl, iconUrl,
height: size.height, height: size.height,
width: size.width,
errorWidget: const FlowySvg(FlowySvgs.toolbar_link_earth_m), errorWidget: const FlowySvg(FlowySvgs.toolbar_link_earth_m),
); );
} }
@ -106,6 +108,7 @@ class LinkInfo {
url: iconUrl, url: iconUrl,
fit: BoxFit.contain, fit: BoxFit.contain,
height: size.height, height: size.height,
width: size.width,
errorWidgetBuilder: (context, error, stackTrace) => errorWidgetBuilder: (context, error, stackTrace) =>
const FlowySvg(FlowySvgs.toolbar_link_earth_m), const FlowySvg(FlowySvgs.toolbar_link_earth_m),
); );

View file

@ -43,7 +43,7 @@ class _MentionLinkBlockState extends State<MentionLinkBlock> {
final parser = LinkParser(); final parser = LinkParser();
_LoadingStatus status = _LoadingStatus.loading; _LoadingStatus status = _LoadingStatus.loading;
final previewController = PopoverController(); final previewController = PopoverController();
LinkInfo? linkInfo; LinkInfo linkInfo = LinkInfo();
bool isHovering = false; bool isHovering = false;
int previewFocusNum = 0; int previewFocusNum = 0;
bool isPreviewHovering = false; bool isPreviewHovering = false;
@ -60,7 +60,7 @@ class _MentionLinkBlockState extends State<MentionLinkBlock> {
int get index => widget.index; int get index => widget.index;
bool get readyForPreview => bool get readyForPreview =>
status == _LoadingStatus.idle && !(linkInfo?.isEmpty() ?? true); status == _LoadingStatus.idle && !linkInfo.isEmpty();
@override @override
void initState() { void initState() {
@ -69,10 +69,10 @@ class _MentionLinkBlockState extends State<MentionLinkBlock> {
parser.addLinkInfoListener((v) { parser.addLinkInfoListener((v) {
if (mounted) { if (mounted) {
setState(() { setState(() {
linkInfo = v; if (v.isEmpty() && linkInfo.isEmpty()) {
if (v.isEmpty()) {
status = _LoadingStatus.error; status = _LoadingStatus.error;
} else { } else {
linkInfo = v;
status = _LoadingStatus.idle; status = _LoadingStatus.idle;
} }
}); });
@ -112,7 +112,7 @@ class _MentionLinkBlockState extends State<MentionLinkBlock> {
borderRadius: BorderRadius.circular(16), borderRadius: BorderRadius.circular(16),
popupBuilder: (context) => readyForPreview popupBuilder: (context) => readyForPreview
? MentionLinkPreview( ? MentionLinkPreview(
linkInfo: linkInfo ?? LinkInfo(), linkInfo: linkInfo,
showAtBottom: showAtBottom, showAtBottom: showAtBottom,
triggerSize: getSizeFromKey(), triggerSize: getSizeFromKey(),
onEnter: (e) { onEnter: (e) {
@ -170,7 +170,7 @@ class _MentionLinkBlockState extends State<MentionLinkBlock> {
HSpace(4), HSpace(4),
Flexible( Flexible(
child: FlowyText( child: FlowyText(
linkInfo?.siteName ?? url, linkInfo.siteName ?? url,
color: theme.textColorScheme.primary, color: theme.textColorScheme.primary,
fontSize: 14, fontSize: 14,
figmaLineHeight: 20, figmaLineHeight: 20,
@ -194,7 +194,7 @@ class _MentionLinkBlockState extends State<MentionLinkBlock> {
child: const CircularProgressIndicator(strokeWidth: 1), child: const CircularProgressIndicator(strokeWidth: 1),
); );
} else { } else {
icon = linkInfo?.buildIconWidget() ?? defaultWidget; icon = linkInfo.buildIconWidget();
} }
return SizedBox( return SizedBox(
height: 20, height: 20,