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 for ability to activate buttons using right click #2622

Merged
merged 17 commits into from
Feb 19, 2019
Merged

Fix for ability to activate buttons using right click #2622

merged 17 commits into from
Feb 19, 2019

Conversation

Comandeer
Copy link
Member

What is the purpose of this pull request?

Bug fix

Does your PR contain necessary tests?

All patches which change the editor code must include tests. You can always read more
on PR testing,
how to set the testing environment and
how to create tests
in the official CKEditor documentation.

This PR contains

  • Unit tests
  • Manual tests

What changes did you make?

I've added additional check if left mouse button was used for click. I also add ability to get info about mouse button from native DOM event in CKEDITOR.tools.getMouseButton.

Closes #2565.

@mlewand mlewand added the review:easy Pull requests that can be reviewed by a Junior Developer before being reviewed by the Reviewer. label Feb 6, 2019
@engineering-this engineering-this self-requested a review February 6, 2019 15:30
@engineering-this engineering-this self-assigned this Feb 6, 2019
Copy link
Contributor

@engineering-this engineering-this left a comment

Choose a reason for hiding this comment

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

There is one issue with Edge.
Right clicking on toolbar items changes editor selection. While any other click outside of an iframe doesn't affect editor selection at all.

'test getMouseButton with native DOM event': function() {
var isIe8 = CKEDITOR.env.ie && CKEDITOR.env.version < 9;

function generateMouseButtonAsserts( inputs ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please move function declaration to end of block.

var isIe8 = CKEDITOR.env.ie && CKEDITOR.env.version < 9;

function generateMouseButtonAsserts( inputs ) {
function generateEvent( button ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above.

@@ -0,0 +1,30 @@
@bender-tags: 4.11.2, 2565, bug, button
Copy link
Contributor

Choose a reason for hiding this comment

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

Please update version tag to 4.11.3.

core/tools.js Outdated
// Added in case when there's no data available. That's the case in some unit test in built version which
// mock event but doesn't put data object.
if ( evt instanceof Event ) {
domEvent = evt;

This comment was marked as resolved.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd rather keep it the way it is. After inlining we'd have two conditionals (ternary operator and &&) in one line.

}

generateMouseButtonAsserts( [
[ CKEDITOR.MOUSE_BUTTON_LEFT, isIe8 ? 1 : CKEDITOR.MOUSE_BUTTON_LEFT ],
Copy link
Contributor

Choose a reason for hiding this comment

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

Small simplification could be done. Ternary operator could be moved to generateEvent param, so changed lines would look like:

assert.areSame( input[ 0 ], CKEDITOR.tools.getMouseButton( generateEvent( input[ isIe8 ? 1 : 0 ] ) ) );
(...)
[ CKEDITOR.MOUSE_BUTTON_LEFT, 1 ],

Improvements for this test case could be also applied on previous one.

var ie8ButtonMap = {
0: 1,
1: 4,
2: 2
Copy link
Contributor

Choose a reason for hiding this comment

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

This function might be reused in some future tests.
Keys '0', '1', '2' doesn't mean a lot. I understand, we can't use computed key names in current es version. So instead we could define them like following:

ie8ButtonMap[ CKEDITOR.MOUSE_BUTTON_LEFT ] = 1;
ie8ButtonMap[ CKEDITOR.MOUSE_BUTTON_MIDDLE ] = 4;
ie8ButtonMap[ CKEDITOR.MOUSE_BUTTON_RIGHT ] = 2;

But thats ugly, and repetitive, so instead maybe just add comment in each line with button name, e.g.:

var ie8ButtonMap = {
	0: 1, // CKEDITOR.MOUSE_BUTTON_LEFT
	(...)

WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

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

Comments sound like a good idea 👍

@Comandeer
Copy link
Member Author

The issue with Edge is present also on current master branch, so it's a separate bug. What's more you must click toolbar button as the first thing after selecting text, clicking anywhere else first and then on button does not trigger the bug. However I don't think there is much sense in reporting it, as it's a real edge case (no pun intended).

Copy link
Contributor

@engineering-this engineering-this left a comment

Choose a reason for hiding this comment

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

Just two small things, everything else looks good to me.

@engineering-this
Copy link
Contributor

I could resolve my own suggestion, but only the first one. For the second GH said 'You are not allowed to resolve suggestions'. So I just manually pushed commit 😂

@f1ames f1ames self-requested a review February 15, 2019 15:20
@f1ames f1ames self-assigned this Feb 18, 2019
Copy link
Contributor

@f1ames f1ames left a comment

Choose a reason for hiding this comment

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

Looks good, just two small things (see comments). Also it seems added unit test are failing on IE9, IE10 🤔

image

image

@Comandeer Comandeer self-assigned this Feb 18, 2019
@Comandeer
Copy link
Member Author

Fixed failing tests. It was connected with too strict conditional checking if the event is instance of native DOM event. Now the function assumes that passed evt option is native DOM event if it doesn't have data property.

I've also refactored button's template according to the advice to be more readable.

@Comandeer Comandeer requested a review from f1ames February 18, 2019 13:15
@f1ames f1ames self-assigned this Feb 19, 2019
@f1ames f1ames merged commit f5699ec into master Feb 19, 2019
@CKEditorBot CKEditorBot deleted the t/2565 branch February 19, 2019 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review:easy Pull requests that can be reviewed by a Junior Developer before being reviewed by the Reviewer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants