Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion packages/format-library/src/link/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ function Edit( {
return;
}

// Close the Link popover if there is no active selection
// after the link was added - this can happen if the user
// adds a link without any text selected.
// We assume that if there is no active selection after
// link insertion there are no active formats.
if ( ! value.activeFormats ) {
editableContentElement.focus();
setAddingLink( false );
return;
}

function handleClick( event ) {
// There is a situation whereby there is an existing link in the rich text
// and the user clicks on the leftmost edge of that link and fails to activate
Expand All @@ -67,7 +78,7 @@ function Edit( {
return () => {
editableContentElement.removeEventListener( 'click', handleClick );
};
}, [ contentRef, isActive ] );
}, [ contentRef, isActive, addingLink, value ] );

function addLink( target ) {
const text = getTextContent( slice( value ) );
Expand Down