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

Merged
merged 3 commits into from Aug 22, 2018

Conversation

Projects
None yet
3 participants
@noisysocks
Member

noisysocks commented Aug 17, 2018

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.

auto-link

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:

npm run test-e2e

Or, for those of us who distrust automation:

  1. Highlight a URL
  2. Click Link or press Cmd+K
  3. The selected URL should immediately become a link
*
* @return {boolean} Whether or not it looks like a URL.
*/
export function isURL( url ) {

This comment has been minimized.

@jorgefilipecosta

jorgefilipecosta Aug 17, 2018

Member

Nice util, I think we may be able to use it in:

if ( linkRegExp.test( pastedText ) ) {

Removing a duplicate regex.

@jorgefilipecosta

jorgefilipecosta Aug 17, 2018

Member

Nice util, I think we may be able to use it in:

if ( linkRegExp.test( pastedText ) ) {

Removing a duplicate regex.

This comment has been minimized.

@noisysocks

noisysocks Aug 20, 2018

Member

I've already replaced that regex 🙂

@noisysocks

noisysocks Aug 20, 2018

Member

I've already replaced that regex 🙂

@jorgefilipecosta

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.

@noisysocks

This comment has been minimized.

Show comment
Hide comment
@noisysocks

noisysocks Aug 20, 2018

Member

Good catch @jorgefilipecosta! I've fixed this in 50c9c01.

Member

noisysocks commented Aug 20, 2018

Good catch @jorgefilipecosta! I've fixed this in 50c9c01.

@noisysocks noisysocks changed the base branch from fix/disappearing-link-selection to master Aug 21, 2018

@jorgefilipecosta

It is working well in my tests 👍

noisysocks added some commits Aug 17, 2018

Automatically create a link when selected text is a URL
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.
Fix URL link editing
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).

@noisysocks noisysocks merged commit d6ddeab into master Aug 22, 2018

2 checks passed

codecov/project 50.9% (-0.03%) compared to a5c89c7
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@noisysocks noisysocks deleted the add/auto-link-selected-urls branch Aug 22, 2018

@noisysocks noisysocks modified the milestones: 3.8, 3.7 Aug 22, 2018

@mtias

This comment has been minimized.

Show comment
Hide comment
@mtias

mtias Aug 30, 2018

Contributor

Thanks for this improvement!

Contributor

mtias commented Aug 30, 2018

Thanks for this improvement!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment