Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#13019 closed Bug (invalid)

Chrome: Unbale to get 'keydown' event

Reported by: Irina Owned by:
Priority: Normal Milestone:
Component: General Version:
Keywords: IBM Cc: Satya Minnekanti

Description (last modified by Piotrek Koszuliński)

Steps to reproduce:

  1. Open any sample in Chrome, clear it's content
  2. Run following in the console:

CKEDITOR.instances.[EDITOR_INSTANCE_ID].document.on('keydown', function(event) {
    console.log('KEYDOWN EVENT');
});
  1. Type few letters, e.g. abc.
    • Result: console will print that keydown event occurred 3 times, e.g. (3)KEYDOWN EVENT
  2. Press enter key
    • Result: key down event not detected and this is expected behaviour for this key
  3. press Backspace key
    • Actual result: key down event not detected

Expected result: console will print that keydown event occurred 4 times, e.g. (4)KEYDOWN EVENT

Change History (6)

comment:1 Changed 4 years ago by Jakub Ś

Resolution: invalid
Status: newclosed
Version: 4.4.7

Please use below code:

editor.on( "pluginsLoaded", function( event ){
	editor.on( 'contentDom', function() {
		var editable = editor.editable();
		//key events should be assigned only to editable as it is the only thing that handles them.
		editable.attachListener( editable, 'keydown', function( e ) { 
			console.log( 'KEYDOWN EVENT' );
		}, null, null, 1 );
	});
});
  1. First off all you should use priorities. CKEditor handles many special keys like Enter or Backspace and once it handles them it may cancel the event in order to prevent native event execution.
  2. Don't use CKE 3.x code. The only proper place to assign event like keydown is editable. In case of document - no matter the priority, cancelled event won't reach it.

comment:2 Changed 4 years ago by John

I urgently require that this ticket be reopened and reinvestigated

Even when using the 'editable.on' for events we are still seeing issues with event handling being handled differently across browsers (IE, Chrome, FF). This seems to be particularly prevalent when the event selection deals with a HTML element (for example a Link, DIV, or NBSP element in the text). Often cursors go missing, and many times it will take several clicks for an action to be completed. Each browser seems to handle these issues in their own distinct way, as opposed to handling the same in each, as expected.

thanks, John

comment:3 Changed 4 years ago by Piotrek Koszuliński

Please report a new issue and provide necessary details to reproduce it. From what you wrote it doesn't seem to be related to this issue, but I can't be sure, because the description you gave is a bit vague.

comment:4 Changed 4 years ago by John

I am seeing an issue with key events not behaving correctly across browsers. I have tried both 'editor.document.on' and 'editable.on' as suggested above. Just as mentioned by Irina above, it seems as though I get different results based on which browser I am using, especially keyDown.

Also, I dont believe it is a different topic - in is related in the sense that it seems to be the same issue only it becomes much more noticeable when there is HTML (Links, DIVs, SPANs, etc...) elements in the text. In the event that I try to remove a HTML element using backspace/delete, often times in certain browsers it will require clicking twice to accomplish this, while in others I cannot remove the element at all. With keyboard arrow navigation often times the cursor seems to disappear when the selection reaches an element.

as odd as it sounds, (because the suggestion above suggests the opposite) - but I was actually seeing more consistent results using 'editor.document.on', whereas now with 'editable.on' I often can hit a key and see no debugs or no proof that the event even occurred.

comment:5 Changed 4 years ago by Piotrek Koszuliński

Please read https://gist.github.com/Reinmar/9665f1630cd6287b4c2b. I hope that it helps. If not, please provide a sample which shows the issue.

comment:6 Changed 4 years ago by Piotrek Koszuliński

Description: modified (diff)
Note: See TracTickets for help on using tickets.
© 2003 – 2017 CKSource – Frederico Knabben. All rights reserved. | Terms of use | Privacy policy