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: Can't open context menu with keyboard shortcut over widget #2958

Merged
merged 24 commits into from
Apr 1, 2019

Conversation

Dumluregn
Copy link
Contributor

@Dumluregn Dumluregn commented Mar 14, 2019

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?

The issue occured only for SHIFT + F10 shortcut (CTRL + SHIFT + F10 was working fine). Therefore I allowed SHIFT keystrokes to be passed to other listeners the same way as CTRL and ALT are which solved the problem.

Closes #1901 .

Copy link
Member

@jacekbogdanski jacekbogdanski left a comment

Choose a reason for hiding this comment

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

Seems to work, however, such change requires unit tests coverage. You can see some examples here:
https://github.com/ckeditor/ckeditor-dev/blob/15c4181d1e6cab08a11d59220a820ef605ef29f7/tests/plugins/widget/undo.js#L287-L312

You wanna know if keystrokes with shift are not canceled, so it should be enough to fire key event with the correct keystroke and check if it didn't return false.

plugins/widget/plugin.js Outdated Show resolved Hide resolved
tests/plugins/widget/manual/contextmenushortcuts.md Outdated Show resolved Hide resolved
tests/plugins/widget/manual/contextmenushortcuts.html Outdated Show resolved Hide resolved
tests/plugins/widget/manual/contextmenushortcuts.html Outdated Show resolved Hide resolved
@f1ames f1ames added the review:easy Pull requests that can be reviewed by a Junior Developer before being reviewed by the Reviewer. label Mar 18, 2019
@jacekbogdanski jacekbogdanski self-assigned this Mar 22, 2019
Copy link
Member

@jacekbogdanski jacekbogdanski left a comment

Choose a reason for hiding this comment

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

Both unit tests you created are fine. They are checking if SHIFT key has not been canceled so the event can be propagated further. However, such test should be probably placed in widgetsintegration.js file because it's more like a generic test case. Although, we will still be missing integration test for context menu. Issue request concerns this plugin, so it makes sense to add an additional test to make sure if the context menu is opened for a widget.

In case of creating such integration test, you will need to find out the whole keyboard handling flow, thus context menu listens on keydown event, but widget issue is placed inside artificial key event handler. In shortcut, you wanna use keydown event on editable, which will be propagated to the context menu and widget by keystrokehandler:

editor.editable().fire( 'keydown', new CKEDITOR.dom.event( { keyCode: CKEDITOR.SHIFT + 121 } ) );

and check if contextMenu event has been fired for widget instance.

CHANGES.md Outdated Show resolved Hide resolved
plugins/widget/plugin.js Outdated Show resolved Hide resolved
tests/plugins/widget/contextmenu.js Show resolved Hide resolved
tests/plugins/widget/contextmenu.js Show resolved Hide resolved
Copy link
Member

@jacekbogdanski jacekbogdanski left a comment

Choose a reason for hiding this comment

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

Only minor refactoring left. Make sure to correct all similar issues in PR pointed out in this R-.

tests/plugins/widget/contextmenu.js Outdated Show resolved Hide resolved
tests/plugins/widget/contextmenu.js Outdated Show resolved Hide resolved
tests/plugins/widget/contextmenu.js Outdated Show resolved Hide resolved
CHANGES.md Outdated Show resolved Hide resolved
tests/plugins/widget/contextmenu.js Outdated Show resolved Hide resolved
Copy link
Member

@jacekbogdanski jacekbogdanski left a comment

Choose a reason for hiding this comment

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

LGTM, a couple of minor issues which I resolve in the upcoming commits. Although, make sure that you agree with my changes.

tests/plugins/widget/widgetsintegration.js Outdated Show resolved Hide resolved
tests/plugins/widget/widgetsintegration.js Outdated Show resolved Hide resolved
tests/plugins/widget/contextmenu.js Outdated Show resolved Hide resolved
tests/plugins/widget/contextmenu.js Show resolved Hide resolved
tests/plugins/widget/manual/contextmenushortcuts.md Outdated Show resolved Hide resolved
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.

The problem with this solution is the fact that it enables all Shift + some key shortcuts when widget is focused. So apart from Shift + F10 all other Shift shortcuts will start to work which may lead to some unexpected results (the list of shortcuts is on our docs page - here and here). For example Shift + Left / Right moves selection to the content end and logs an error:

widget shift issues

Shift + Enter inserts new paragraph before widget, which upon undoing logs an error:

widget shift issues 2

Shift + Tab moves selection out of the editor, while before it was simply disabled not changing selection.

While I agree that there might be some shortcuts which could be enabled, most of them were disabled on focused widget for a reason and won't work or will break something. My suggestion is to simply enable Shift + F10 combination.


When it comes to manual test we usually try to keep things simple not loading too much plugins. However, in this case, shortcuts are provided by few plugins and without them we cannot check if something is broken (cases mentioned above will not fail on provided manual test). My suggestion here is to add at least one plugin which has its own shortcuts and extend test by the additional case checking if this shortcut still does not have any effect while widget is focused.

Also I would add both block and inline widgets there (now there is only inline one).

@Dumluregn Dumluregn requested a review from f1ames April 1, 2019 12:00
@f1ames f1ames self-assigned this Apr 1, 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.

Added unit tests are failing on Safari:

Screen Shot 2019-04-01 at 14 49 45

See also review comments (some minor polishing).

tests/plugins/widget/manual/contextmenushortcuts.md Outdated Show resolved Hide resolved
plugins/widget/plugin.js Outdated Show resolved Hide resolved
@Dumluregn
Copy link
Contributor Author

I double-checked the tests on Safari and with clear cache they pass in my browser (Version 12.0.3 (14606.4.5)).
Screenshot 2019-04-01 at 15 48 39
Screenshot 2019-04-01 at 15 48 51

@Dumluregn Dumluregn requested a review from f1ames April 1, 2019 13:51
@f1ames f1ames self-assigned this Apr 1, 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.

I double-checked the tests on Safari and with clear cache they pass in my browser.

Seems to be also a cache issue on my side.


There is one problem with positioning context menu in IE8 but it is not related to this fix so I will report a follow-up.

@f1ames f1ames merged commit 92be5c2 into master Apr 1, 2019
@CKEditorBot CKEditorBot deleted the t/1901 branch April 1, 2019 16:32
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.

3 participants