@@ -22,7 +22,7 @@ import {
2222 __experimentalLinkControl as LinkControl ,
2323 store as blockEditorStore ,
2424} from '@wordpress/block-editor' ;
25- import { useSelect } from '@wordpress/data' ;
25+ import { useDispatch , useSelect } from '@wordpress/data' ;
2626
2727/**
2828 * Internal dependencies
@@ -52,15 +52,22 @@ function InlineLinkUI( {
5252 // Get the text content minus any HTML tags.
5353 const richTextText = richLinkTextValue . text ;
5454
55- const { createPageEntity, userCanCreatePages } = useSelect ( ( select ) => {
56- const { getSettings } = select ( blockEditorStore ) ;
57- const _settings = getSettings ( ) ;
58-
59- return {
60- createPageEntity : _settings . __experimentalCreatePageEntity ,
61- userCanCreatePages : _settings . __experimentalUserCanCreatePages ,
62- } ;
63- } , [ ] ) ;
55+ const { selectionChange } = useDispatch ( blockEditorStore ) ;
56+
57+ const { createPageEntity, userCanCreatePages, selectionStart } = useSelect (
58+ ( select ) => {
59+ const { getSettings, getSelectionStart } =
60+ select ( blockEditorStore ) ;
61+ const _settings = getSettings ( ) ;
62+
63+ return {
64+ createPageEntity : _settings . __experimentalCreatePageEntity ,
65+ userCanCreatePages : _settings . __experimentalUserCanCreatePages ,
66+ selectionStart : getSelectionStart ( ) ,
67+ } ;
68+ } ,
69+ [ ]
70+ ) ;
6471
6572 const linkValue = useMemo (
6673 ( ) => ( {
@@ -122,8 +129,23 @@ function InlineLinkUI( {
122129 inserted ,
123130 linkFormat ,
124131 value . start ,
125- value . end + newText . length
132+ value . start + newText . length
126133 ) ;
134+
135+ onChange ( newValue ) ;
136+
137+ // Close the Link UI.
138+ stopAddingLink ( ) ;
139+
140+ // Move the selection to the end of the inserted link outside of the format boundary
141+ // so the user can continue typing after the link.
142+ selectionChange ( {
143+ clientId : selectionStart . clientId ,
144+ identifier : selectionStart . attributeKey ,
145+ start : value . start + newText . length + 1 ,
146+ } ) ;
147+
148+ return ;
127149 } else if ( newText === richTextText ) {
128150 newValue = applyFormat ( value , linkFormat ) ;
129151 } else {
0 commit comments