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

Context menu is incorrectly positioned when opened with Shift-F10 #1451

Closed
earshinov opened this issue Jan 15, 2018 · 7 comments
Closed

Context menu is incorrectly positioned when opened with Shift-F10 #1451

earshinov opened this issue Jan 15, 2018 · 7 comments
Assignees
Labels
accessibility Issue related to accessibility. plugin:contextmenu The plugin which probably causes the issue. status:confirmed An issue confirmed by the development team. target:minor Any docs related issue that can be merged into a master or major branch. type:bug A bug.
Milestone

Comments

@earshinov
Copy link

Are you reporting a feature request or a bug?

Bug.

I have not found any relevant issues mentioning context menu and F10.

Reproduction steps

  1. Find any CKEDITOR with some text. The editor from CKEDITOR 4 homepage will do.
  2. Position the text cursor anywhere in the text inside the editor.
  3. Press Shift-F10.

Expected result

The context menu should appear next to the text cursor.

Actual result

The context menu appears somewhere else. In case of the editor on the homepage the menu is opened close to the top left corner of the contents of the editor.

Other details

  • Browser: Google Chrome 63.0.3239.132
  • OS: Windows 7 x64
  • CKEditor version: the issue reproduces in 4.5.9, 4.8.0
  • Installed CKEditor plugins: tested in the "standard" distribution of CKEDITOR
@earshinov
Copy link
Author

CKEDITOR handles Shift-F10 and Ctrl-Shift-F10 itself instead of relying on the browser.

contextmenu/plugin.js:

editor.setKeystroke( CKEDITOR.SHIFT + 121 /*F10*/, 'contextMenu' );
editor.setKeystroke( CKEDITOR.CTRL + CKEDITOR.SHIFT + 121 /*F10*/, 'contextMenu' );

Actually, many browsers support these shortcuts out of the box, emitting contextmenu event. In such browsers, everything would work fine if CKEDITOR didn't override the default browser behaviour. I have checked latest Chrome, Firefox, and Microsoft Edge - only the latest does not support Shift-F10.

May it be possible to employ browser detection here, perhaps enabling custom handling only in env.ie? Of course one needs to be sure that everything works in older Chrome, Firefox, Safari etc.

@mlewand mlewand added type:bug A bug. status:confirmed An issue confirmed by the development team. plugin:contextmenu The plugin which probably causes the issue. accessibility Issue related to accessibility. target:minor Any docs related issue that can be merged into a master or major branch. labels Jan 15, 2018
@mlewand
Copy link
Contributor

mlewand commented Jan 15, 2018

Thnx @earshinov, I'm able to reproduce the issue. Preferred option is to have the same logic for all browsers, without sniffing - so if the positioning can be fixed let's do this and set it for all browsers.

If that would be for some reason impossible, then we can think about falling back to browser sniffing.

Workaround

Based on your preference and your feedback, what I can suggest is to disable our custom handling for non IE browsers. Add below code to your config.js:

	if ( !CKEDITOR.env.ie ) {
		config.keystrokes = [
			[ CKEDITOR.SHIFT + 121 /*F10*/, null ]
		]
	}

@earshinov
Copy link
Author

@mlewand, Yes, this is exactly the solution we use. Thankfully, we have CKEDITOR running on a page inside embedded Chromium (CEF), so we can rely on the browser engine to handle these shortcuts for us.

@earshinov
Copy link
Author

There is another possible solution I would like to suggest.

Presently, floatpanel plugin, which does the actual positioning for the context menu, just assumes offsetX and offsetY to be 0 when they are unavailable:

floatpanel/plugin.js:

showBlock: function( /* ... */ ) {
	// ...
	left = position.x + ( offsetX || 0 ) - positionedAncestorPosition.x,
	top = position.y + ( offsetY || 0 ) - positionedAncestorPosition.y;
	// ...
}

This is obviously incorrect. Instead, when mouse coordinates are unavailable, as in keyboard event handlers, CKEDITOR could rely on the position of the text cursor. I guess, Range.getClientRects() can be used for this purpose, which happens to be failrly cross-browser.

@mlewand
Copy link
Contributor

mlewand commented Jan 15, 2018

@earshinov thanks for a nice investigation. The fix should be applied in contextmenu plugin and picking position from a range seems like a good idea 👍

The fallback to 0 in the generic plugin is ok, as it's not only used by context menu, but also other ui plugins.

I can see that getClientRects() is not supported on IE8, which is not a show stopper for us. It might be worth checking if there are other APIs in IE8 to get it working there too, but if not, it could just keep fallback x,y=0 values.

@Comandeer
Copy link
Member

Merged into next, will be released in 4.10.2.

@mlewand
Copy link
Contributor

mlewand commented Sep 5, 2018

Note that you can already have a peek at the working solution in our nightly preview 😉

@mlewand mlewand modified the milestones: 4.10.2, 4.11.0 Oct 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accessibility Issue related to accessibility. plugin:contextmenu The plugin which probably causes the issue. status:confirmed An issue confirmed by the development team. target:minor Any docs related issue that can be merged into a master or major branch. type:bug A bug.
Projects
None yet
Development

No branches or pull requests

4 participants