Skip to content
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

fix/[#21440] Copy/cut input values copying entire block #21457

Merged
merged 1 commit into from
Apr 8, 2020

Conversation

kirilzh
Copy link
Contributor

@kirilzh kirilzh commented Apr 7, 2020

Description

In block-editor/src/components/copy-handler/index.js this check does not pass

// Let native copy behaviour take over in input fields.
if ( ! hasMultiSelection() && documentHasSelection() ) {
	return;
}

because documentHasSelection() returns false. Going deeper we see there’s a check if a text fields has a selection

function documentHasSelection() {
	if ( isTextField( document.activeElement ) ) {
		return true;
	}

	const selection = window.getSelection();
	const range = selection.rangeCount ? selection.getRangeAt( 0 ) : null;

	return range && ! range.collapsed;
}

I then stumbled upon this. Hence I added a function checking only <input type="number" />.

How has this been tested?

In both Chrome and FF on MacOS.

Types of changes

Bug fix (non-breaking change) which fixes #21440 .

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.

@kirilzh kirilzh requested a review from ellatrix as a code owner April 7, 2020 13:45
@@ -480,6 +494,10 @@ export function documentHasSelection() {
return true;
}

if ( isNumberInput( document.activeElement ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add this inside isTextField or should it be a separate function? Or more precisely, do we consider a "number" input as a text field? I might think yes but curious what others think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially I extended isTextField but later I asked myself the same question and to me it makes more sense to have them separated. I don't consider numbers as text per se. Also curious what others think : )

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good to me, I'll do some testing

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to work very well :) Thanks for the fix.

@youknowriad youknowriad merged commit a3a06e5 into WordPress:master Apr 8, 2020
@youknowriad youknowriad added [Type] Bug An existing feature does not function as intended [Feature] Paste labels Apr 8, 2020
@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Apr 8, 2020
@github-actions
Copy link

github-actions bot commented Apr 8, 2020

Congratulations on your first merged pull request, @kirilzh! We'd like to credit you for your contribution in the post announcing the next WordPress release, but we can't find a WordPress.org profile associated with your GitHub account. When you have a moment, visit the following URL and click "link your GitHub account" under "GitHub Username" to link your accounts:

https://profiles.wordpress.org/me/profile/edit/

And if you don't have a WordPress.org account, you can create one on this page:

https://login.wordpress.org/register

Kudos!

@github-actions github-actions bot added this to the Gutenberg 7.9 milestone Apr 8, 2020
@tomusborne
Copy link

This has fixed the copying part of the issue, but I'm still seeing an issue once the value is pasted back into the field. The pasted value replaces the block itself, instead of being added to the field.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Paste First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Copy/cut input values copying entire block/removing block
3 participants