Opened 13 years ago

Last modified 9 years ago

#7229 new New Feature

Request for relaying cut and copy events to the editor instance

Reported by: Arne Owned by:
Priority: Normal Milestone:
Component: General Version:
Keywords: Cc:

Description

Request for normalizing cut, copy and paste events in the editor across browsers. In version 3.5.2 only the 'paste' event is relayed to the editor object. Would be very convenient if 'cut' and 'copy' could also be relayed.

The specific use case is having to add attributes to the elements in a selection prior to cutting/copying. These are then parsed when pasted back into the editor.

Some quick research gave me the following summary:

I ran the following code in each of the browsers' developer tools

var body = CKEDITOR.instances.editor1.document.getBody();
var logger = function (name) {
    return function () {console.log(name);};
};
body.on('beforepaste', logger('beforepaste'));
body.on('paste', logger('paste'));
body.on('beforecut', logger('beforecut'));
body.on('cut', logger('cut'));
body.on('beforecopy', logger('beforecopy'));
body.on('copy', logger('copy'));

and registered the events fired:

Opera Version: 11.00, Build: 1156, WinXP

Cut: none
Copy: none
Paste: 
  beforepaste 
  paste

Google Chrome 9.0.597.98, WinXP

Cut:
  beforecut
  cut
Copy:
  beforecopy
  copy
Paste:
  beforepaste
  paste

Firefox 3.6.13, WinXP

Cut:
  cut
Copy:
  copy
Paste:
  beforepaste
  paste

IE8, Windows Server 2003

Cut:
  beforecut
  cut
Copy:
  beforecopy
  copy
Paste:
  beforepaste
  paste

IE also fires extra unlisted ones due to calling "queryCommandEnabled('paste')" in clipboard plugin.

Change History (3)

comment:1 Changed 9 years ago by Jakub Ś

From what I have checked events like beforecopy or beforecut are not natively supported by e.g. Firefox: http://help.dottoro.com/ljrlxaae.php
http://help.dottoro.com/ljkadrvv.php
http://help.dottoro.com/ljxqbxkf.php
https://developer.mozilla.org/en-US/docs/Web/Events

When looking at beforePaste event in CKEditor 4 http://docs.ckeditor.com/#!/api/CKEDITOR.editor-event-beforePaste I have noticed that it is recommended to use priorities if someone wants to do some custom actions before pasting content. The same can be used for cut and copy events.

@arne - I know this request has been reported long time ago but could you perhaps explain in more detail why did you need beforecut, beforecopy and changing priorities isn't better alternative here?

comment:2 Changed 9 years ago by Arne

I think I managed to achieve what I needed using the cut, copy and paste in all browsers but Opera. What I needed was to add metadata/contextual data to the elements in the selection before the browsers copied the selection to the clipboard. As far as I remember that worked with the cut, copy and paste events. Regarding the availability of the before* events I would just have liked the editor to be consistent across browsers. I see your point on priorities.

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

We've been working on this a lot recently, because CKEditor 4.5.0 introduced many new features around the clipboard. Drag and drop is now nearly fully covered by our events, but it was a huge pain to do this. A lot of tricks were needed and it took a lot of time. We also improved copy and cut, but only on some browsers. There's no way to unify all this across all browsers at the moment. Chrome works best, but other browsers are either disappointing (like Firefox which doesn't allow to set custom data in the clipboard) or totally disastrous like all IEs (including even Spartan at the moment), where there's still no clipboard API except the legacy one which is useless.

The question is whether it makes sense to expose copy and cut events at the moment. In my opinion, due to various browsers limitations these events would be unfunctional. Plus, it would be a lot of work for us.

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