-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Conversation
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.
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.
tests/core/tools.js
Outdated
'test getMouseButton with native DOM event': function() { | ||
var isIe8 = CKEDITOR.env.ie && CKEDITOR.env.version < 9; | ||
|
||
function generateMouseButtonAsserts( inputs ) { |
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.
Please move function declaration to end of block.
tests/core/tools.js
Outdated
var isIe8 = CKEDITOR.env.ie && CKEDITOR.env.version < 9; | ||
|
||
function generateMouseButtonAsserts( inputs ) { | ||
function generateEvent( button ) { |
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.
Same as above.
@@ -0,0 +1,30 @@ | |||
@bender-tags: 4.11.2, 2565, bug, button |
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.
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.
This comment was marked as resolved.
Sorry, something went wrong.
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'd rather keep it the way it is. After inlining we'd have two conditionals (ternary operator and &&
) in one line.
tests/core/tools.js
Outdated
} | ||
|
||
generateMouseButtonAsserts( [ | ||
[ CKEDITOR.MOUSE_BUTTON_LEFT, isIe8 ? 1 : CKEDITOR.MOUSE_BUTTON_LEFT ], |
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.
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.
tests/plugins/button/button.js
Outdated
var ie8ButtonMap = { | ||
0: 1, | ||
1: 4, | ||
2: 2 |
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.
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?
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.
Comments sound like a good idea 👍
The issue with Edge is present also on current |
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.
Just two small things, everything else looks good to me.
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 😂 |
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.
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 I've also refactored button's template according to the advice to be more readable. |
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
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.