-
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 activating various UI items via right click #2859
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.
I don't like magic numbers for IE8 passed as a mouse button keystroke. I see that IE8 returns different mouse button code than other browsers, however, the mapping should be done explicitly to avoid guessing what's going on. I'm wondering if we could just make reversed getMouseButton
mapping public?
## Procedure | ||
|
||
1. Open console. | ||
2. Open editor's context menu. |
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.
Maybe Open editor's context menu by right-clicking its content.
to make it more brainless?
|
||
### Expected result: | ||
|
||
Focus is moved to the clicked item. |
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.
Not valid for a single context menu item which is already preselected.
|
||
// (#2858) | ||
'test right-clicking menu items': function() { | ||
if ( !CKEDITOR.env.ie ) { |
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 would also enable this test for other browsers for regression protection.
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.
@Comandeer can you refer to this comment? Is this similar situation as with other tests that you find the regressions very unlikely to happen?
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.
Yes, it's de facto impossible. We use click
event in every other browser, so right click will never occur in the first place. In IE it occurred as we use mouseup
event there due to some nasty bug in IE's native image controls.
tests/core/tools.js
Outdated
'<a href="#" onmouseup="this.setAttribute(\'data-button\',event.button);return false;">Link</a>' ); | ||
|
||
CKEDITOR.tools.fireElementEventHandler( link, 'onmouseup', { | ||
button: 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.
Please, use enum values for readability (CKEDITOR.MOUSE_BUTTON_RIGHT
). Update the rest of the proposed tests with enum values.
tests/plugins/panel/panel.js
Outdated
|
||
block._.markFirstDisplayed(); | ||
|
||
block.onKeyDown( 13 ); |
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.
Add info about pressed keystroke e.g. block.onKeyDown( 13 ); // ENTER
.
|
||
// (#2565) | ||
'test right-clicking combo': function() { | ||
if ( !CKEDITOR.env.ie ) { |
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.
Again, I think it makes sense to enable test for all browsers.
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 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.
As I stated there, I do not think such regression is even possible.
plugins/panel/plugin.js
Outdated
// We must pass info about clicked button (#2857). | ||
CKEDITOR.tools.fireElementEventHandler( focusable, 'on' + keyAction, { | ||
button: ( CKEDITOR.env.ie && ( CKEDITOR.env.version < 9 || CKEDITOR.env.ie6Compat ) ) ? | ||
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.
This IE8 magic number which additionally can be mistaken with a middle button click (thus 1 == CKEDITOR.MOUSE_BUTTON_MIDDLE
should be replaced with correct mapping.
I've replaced most of magic numbers with bilateral mouse button normalization via newly added I didn't enable tests in any other browsers, as I don't see any reason to do it. The whole issue originates from the fact that we use
There is no point of switching |
I see that introduced changes caused CI to fail due to keyboard handling in emoji. I'll fix it. |
I've fixed incorrect handling of keyboard in emoji plugin, using the same technique that was already used in our old approach: if there isn't |
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.
Tests checking if right click focuses item fails e.g.:
tests/plugins/listblock/manual/rightclick
tests/plugins/menu/manual/rightclick
Right click doesn't focus clicked item, you can verify it by right-clicking item and pressing enter. In that case, the default option will be applied instead of the selected one. Also, there is no visible focus for context menu.
core/tools.js
Outdated
@@ -1466,26 +1466,72 @@ | |||
* @since 4.7.3 | |||
* @param {CKEDITOR.dom.event/Event} evt DOM event. Since 4.11.3 a native `MouseEvent` instance can be passed. | |||
* @returns {Number|Boolean} Returns a number indicating the mouse button or `false` | |||
* if the mouse button cannot be determined. | |||
* if the mouse button cannot be determined. The mouse button is normalized using {@link CKEDITOR.tools#normalizeMouseButton}. |
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.
Do we need this info revealing implementation details?
core/tools.js
Outdated
* | ||
* ``` | ||
* +--------------+------+----------------+ | ||
* | Mouse button | IE | Other browsers | |
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.
Maybe IE
-> IE8 / IE9 QM / IE9 CM
so you need quick glimpse to find out different mappings for these browsers?
This is the mistake in test description, caused by the fact that visible focus indicator (outline) is in fact moved to the clicked item. I fixed tests descriptions. I've also rebased the whole PR onto latest |
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.
core/dom/element.js
Outdated
* } ); | ||
* ``` | ||
* | ||
* @since 4.11.4 |
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 tags across all changes.
core/tools.js
Outdated
|
||
if ( mapping[ 0 ] === button && reverse ) { | ||
return mapping[ 1 ]; | ||
} else if ( !reverse && mapping[ 1 ] === 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.
else if
could be replaced with simpler if
condition thus return statement.
}, | ||
|
||
/* | ||
* Fires specified mouse event on given element |
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.
Missing dot, block comment should start with two *
. Also grammar:
Fires specified mouse event on the given element.
core/dom/element.js
Outdated
*/ | ||
fireEventHandler: function( eventName, evt ) { | ||
var handlerName = 'on' + eventName, | ||
element = this.$; |
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.
What do you think about renaming native element with $
prefix? I.e. $element
. I know it's not something we are doing in our code base but makes code much more readable for me.
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'm not a big fan of it. IMO the name of the variable is readable enough on its own. TBH I'm more eager to change to something like nativeElement
than add $
to the beginning – as it would be readable also for users that do not know the convention.
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.
nativeElement
also works for me 👍
CHANGES.md
Outdated
@@ -12,6 +12,9 @@ Fixed Issues: | |||
|
|||
* [#2672](https://github.com/ckeditor/ckeditor-dev/issues/2672): Fixed: When resizing [Enhanced Image](https://ckeditor.com/cke4/addon/image2) to minimum size with a resizer the image dialog doesn't show actual values. | |||
* [#1478](https://github.com/ckeditor/ckeditor-dev/issues/1478): Fixed: Custom colors added to [Color Button](https://ckeditor.com/cke4/addon/colorbutton) via [`config.colorButton_colors`](https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_config.html#cfg-colorButton_colors) in form label/code don't work correctly. | |||
* [#2845](https://github.com/ckeditor/ckeditor-dev/issues/2845): [Rich Combo](https://ckeditor.com/cke4/addon/richcombo) reacts to right mouse button click. | |||
* [#2857](https://github.com/ckeditor/ckeditor-dev/issues/2857): [List Block](https://ckeditor.com/cke4/addon/listblock) items react to right mouse button click. | |||
* [#2858](https://github.com/ckeditor/ckeditor-dev/issues/2858): [Menu](https://ckeditor.com/cke4/addon/menu) items react to right mouse button click. |
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'm wondering about some entry change log merge here as they have mostly the same message. 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.
I was also thinking about it, but I looked through the whole changelog and didn't spot anything like that. Because of that I decided to create separate entries.
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.
Actually I got an idea, how to do it. bed3e35 shows the proposed solution.
[ci skip] Co-Authored-By: Krzysztof Krztoń <k.krzton@cksource.com>
Rebased onto latest |
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.
LGTM 👍 Well done @Comandeer @jacekbogdanski 🎉
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 is the proposed changelog entry for this pull request?
What changes did you make?
I've fixed ability to use rich combos, listblocks and menus with right mouse button.
To do so I had to add
CKEDITOR.tools.fireElementEventHandler
to be able to emulatemouseup
events with correct mouse button info in keystrokes handler inpanel
.Closes #2845.
Closes #2857.
Closes #2858.
Closes #2975.