Skip to content

Commit

Permalink
Force stop editing link to remove activeFormats
Browse files Browse the repository at this point in the history
  • Loading branch information
getdave committed Jan 10, 2024
1 parent 656bfb1 commit 95d495b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
13 changes: 13 additions & 0 deletions packages/format-library/src/link/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
isCollapsed,
insert,
create,
concat,
} from '@wordpress/rich-text';
import { isURL, isEmail } from '@wordpress/url';
import {
Expand Down Expand Up @@ -64,6 +65,18 @@ function Edit( {

function stopAddingLink( returnFocus = true ) {
setAddingLink( false );

// Remove any active formats.
// Cloning the existing value has the effect of removing
// any active formats and is roughly equivalent to the
// following mutation:
// value.activeFormats = [];
const newValue = concat( value );

// Update to force format to no longer be active.
onChange( newValue );

// Handle focus
if ( returnFocus ) {
onFocus();
}
Expand Down
13 changes: 0 additions & 13 deletions packages/format-library/src/link/inline.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,6 @@ function InlineLinkUI( {
}

function onChangeLink( nextValue ) {
// LinkControl calls `onChange` immediately upon the toggling a setting.
// Before merging the next value with the current link value, check if
// the setting was toggled.
const didToggleSetting =
linkValue.opensInNewTab !== nextValue.opensInNewTab &&
nextValue.url === undefined;
// Merge the next value with the current link value.
nextValue = {
...linkValue,
Expand Down Expand Up @@ -180,16 +174,9 @@ function InlineLinkUI( {
newValue.start = newValue.end;

// Hides the Link UI.
newValue.activeFormats = [];
onChange( newValue );
}

// Focus should only be shifted back to the formatted segment when the
// URL is submitted.
if ( ! didToggleSetting ) {
stopAddingLink();
}

if ( ! isValidHref( newUrl ) ) {
speak(
__(
Expand Down

0 comments on commit 95d495b

Please sign in to comment.