Opened 9 years ago

Last modified 9 years ago

#14300 confirmed Bug

Cut Copy events attached do other element than editable are no longer cancellable.

Reported by: Jakub Ś Owned by:
Priority: Low Milestone:
Component: General Version: 4.5.0
Keywords: Cc:

Description

Steps to reproduce

Below code works until CKE 4.4.8

editor.on('contentDom', function(){
var editable = editor.editable();
editable.attachListener( editor.document, 'cut',  function(ev){
        console.log('logic');
        ev.data.preventDefault();
        return false;
}, null, null, 0);
});

This code works in all versions:

editor.on('contentDom', function(){
   var editable = editor.editable();
   editable.attachListener( editable, 'cut',  function(ev){ //here
         console.log('logic');
         ev.data.preventDefault();
         //ev.cancel();
         return false;
   }, null, null, 0);              
});    

and so does this one:

editor.on('contentDom', function(){
    var editable = editor.editable()
    editable.on( 'cut',  function(ev){
         ev.data.preventDefault();
         return false;
    }, null, null, 0);
});

Was this planned or is this a bug?

Change History (2)

comment:1 Changed 9 years ago by Piotr Jasiun

This is because CKEditor since version 4.5.0 use custom cut and copy which is attached to the events on the editable element: https://github.com/ckeditor/ckeditor-dev/blob/master/plugins/clipboard/plugin.js#L531-L550 Event on the editable is fired, before the event on the document, so the custom cut/copy handling will be executed before your document listener, what is the reason why it does not prevent cutting.

We could do the research and try to attach custom cut/copy handling to the document, but I do not think it is the right way. Especially then you think about the inline editor. In such editor the listener attached to the document may be prevented be code outside the editor.

Is the fact that canceling event should be done on the editable, not the document it a reason of any issue?

comment:2 Changed 9 years ago by Jakub Ś

Priority: NormalLow
Status: newconfirmed
Summary: Events attached do document are no longer prevented.Cut Copy events attached do other element than editable are no longer cancellable.

We have agreed with @m.lewandowski that this is an issue however it is rare case that users will be attaching cut/copy events to other elements than editable thus we give it low priority.

In 99,99% cases an editable and for widgets nested editable will be used.

Version 0, edited 9 years ago by Jakub Ś (next)
Note: See TracTickets for help on using tickets.
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy