-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Automatically create a link when selected text is a URL #9067
Conversation
packages/url/src/test/index.test.js
Outdated
]; | ||
|
||
forEach( urls, ( url ) => { | ||
expect( isURL( url ) ).toBe( true ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
equivalent to: expect( every( urls, isURL ) ).toBe( true );
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 0d218ad
* | ||
* @return {boolean} Whether or not it looks like a URL. | ||
*/ | ||
export function isURL( url ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice util, I think we may be able to use it in:
if ( linkRegExp.test( pastedText ) ) { |
Removing a duplicate regex.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've already replaced that regex 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
href
should be instantly created.As part of this, I pulled an existing link regular expression out into its own
isURL
function that lives in the@wordpress/url
package. 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: