Skip to content

Commit

Permalink
Fix redundant link preview display when link text includes protocol i…
Browse files Browse the repository at this point in the history
…n LinkControl.
  • Loading branch information
amitraj2203 committed May 21, 2024
1 parent a217e57 commit e934740
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import {
__experimentalTruncate as Truncate,
} from '@wordpress/components';
import { useCopyToClipboard } from '@wordpress/compose';
import { filterURLForDisplay, safeDecodeURI } from '@wordpress/url';
import {
filterURLForDisplay,
safeDecodeURI,
removeProtocol,
} from '@wordpress/url';
import { Icon, globe, info, linkOff, edit, copySmall } from '@wordpress/icons';
import { __unstableStripHTML as stripHTML } from '@wordpress/dom';
import { useDispatch, useSelect } from '@wordpress/data';
Expand Down Expand Up @@ -59,6 +63,9 @@ export default function LinkPreview( {
! isEmptyURL &&
stripHTML( richData?.title || value?.title || displayURL );

const isTitleRedundant =
value?.url && removeProtocol( displayTitle ) === displayURL;

let icon;

if ( richData?.icon ) {
Expand Down Expand Up @@ -112,7 +119,7 @@ export default function LinkPreview( {
{ displayTitle }
</Truncate>
</ExternalLink>
{ value?.url && displayTitle !== displayURL && (
{ ! isTitleRedundant && (
<span className="block-editor-link-control__search-item-info">
<Truncate numberOfLines={ 1 }>
{ displayURL }
Expand Down

0 comments on commit e934740

Please sign in to comment.