Automatically create a link when selected text is a URL#9067
Automatically create a link when selected text is a URL#9067noisysocks merged 3 commits intomasterfrom
Conversation
packages/url/src/test/index.test.js
Outdated
| ]; | ||
|
|
||
| forEach( urls, ( url ) => { | ||
| expect( isURL( url ) ).toBe( true ); |
There was a problem hiding this comment.
equivalent to: expect( every( urls, isURL ) ).toBe( true );
| * | ||
| * @return {boolean} Whether or not it looks like a URL. | ||
| */ | ||
| export function isURL( url ) { |
There was a problem hiding this comment.
Nice util, I think we may be able to use it in:
Removing a duplicate regex.
There was a problem hiding this comment.
I've already replaced that regex 🙂
jorgefilipecosta
left a comment
There was a problem hiding this comment.
Nice feature 👍
It is working well I think we have a small bug that we should address before the merge. After we add a link using this method if we click right away on the edit button nothing happens the edit button does not work. If we select other block and then come back and press edit things work well.
|
Good catch @jorgefilipecosta! I've fixed this in 50c9c01. |
543da2f to
47d0bd8
Compare
0f90d62 to
beee381
Compare
jorgefilipecosta
left a comment
There was a problem hiding this comment.
It is working well in my tests 👍
When a URL is selected and the Link button is clicked or the Link keyboard shortcut is pressed, a link with that URL set as its href should be instantly created.
Fixes a bug that prevented the user from selecting a link which has text that looks like a URL and clicking Edit. We accomplish this by distinguishing between editing a link (isEditingLink) and adding a new link (isAddingLink).
beee381 to
79f19e2
Compare
|
Thanks for this improvement! |
Closes #3513.
When a URL is selected and the Link button is clicked or the Link keyboard shortcut is pressed, a link with that URL set as its
hrefshould be instantly created.As part of this, I pulled an existing link regular expression out into its own
isURLfunction that lives in the@wordpress/urlpackage. Not sure if it's actually a useful helper function, though—happy to go back on this decision.To test:
Or, for those of us who distrust automation: