-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Overwriting dataTransfer data on 'clipboardInput' event seems to have no effect on pasting #2675
Comments
I wonder whether it'd be better to rewrite that code snippet mentioned in the docs or add support for always available |
We can change the snippet (we should because the code does not work). The question is if there is any other reliable way to pre-process data in the |
And on
will be needed probably. |
Can't we block Like this: this.listenTo( editor.editing.view, 'clipboardInput', ( evt, data ) => {
const content = customTransform( data.dataTransfer.get( 'text/html' ) );
const transformedContent = transform( content );
editor.plugins.get( 'Clipboard' ).paste( transformedContent );
} ); |
☝️ Yes, I think we could do this, haven't thought about that TBH. It makes sense in this case 👍 So we are just left with incorrect docs. Should it be adjusted to suggest the above method also? |
Yup. Once we'll create it we can change the docs. |
@Reinmar just one more thing, I refactored the sample you posted and it looks like this: this.listenTo( editor.editing.view.document, 'clipboardInput', ( evt, data ) => {
evt.stop();
const htmlData = customTransform( data.dataTransfer.get( 'text/html' ) );
const transformedContent = transform( htmlData );
const content = htmlDataProcessorInstance.toView( content );
editor.plugins.get( 'Clipboard' ).fire( 'inputTransformation', { content } );
} ); I have some doubts, because of the fact that No if we will add And then you will have Now, the I know I have covered two topics here, but they are both connected to this issue and the way how clipboard works (and how we would like to use it). |
I worked on the docs a bit in 75f4eb7. I got rid of that incorrect example and replaced it with explanation how more or less you can use that event. However, we still need to think on what to do with it... |
OK, I agree that tasks like retrieving the content and firing So, in other words, the default listener instead of looking like this: this.listenTo( viewDocument, 'clipboardInput', ( evt, data ) => {
const dataTransfer = data.dataTransfer;
let content = '';
if ( dataTransfer.getData( 'text/html' ) ) {
content = normalizeClipboardHtml( dataTransfer.getData( 'text/html' ) );
} else if ( dataTransfer.getData( 'text/plain' ) ) {
content = plainTextToHtml( dataTransfer.getData( 'text/plain' ) );
}
content = this._htmlDataProcessor.toView( content );
this.fire( 'inputTransformation', { content } );
view.scrollToTheSelection();
}, { priority: 'low' } ); Would look like this: this.listenTo( viewDocument, 'clipboardInput', ( evt, data ) => {
const content = clipboardPlugin.getClipboardContent( data.dataTransfer );
clipboardPlugin.insertContent( content, data );
}, { priority: 'low' } ); And a listener which overrides the default behaviour: this.listenTo( viewDocument, 'clipboardInput', ( evt, data ) => {
const content = clipboardPlugin.getClipboardContent( data.dataTransfer );
const transformedContent = someCustomTransformation( content );
clipboardPlugin.insertContent( transformedContent, data );
evt.stop();
} ); However, that's a hypothetical use because for those kinds of transformations you should use |
OTOH, if the only reason to listen to |
Ok, I see. But with the code you mentioned above: this.listenTo( viewDocument, 'clipboardInput', ( evt, data ) => {
const content = clipboardPlugin.getClipboardContent( data.dataTransfer );
clipboardPlugin.insertContent( content, data );
}, { priority: 'low' } ); which could be default clipboard paste handling, the Also overwriting default code like: this.listenTo( viewDocument, 'clipboardInput', ( evt, data ) => {
const content = clipboardPlugin.getClipboardContent( data.dataTransfer );
const transformedContent = someCustomTransformation( content );
clipboardPlugin.insertContent( transformedContent, data );
evt.stop();
} ); will prevent any further content processing which may take place in other plugins. It seems quite tricky, from one hand it will be good to have one event which will do initial data extraction (like fetching data from Maybe we could go with only one event like
All listeners will have access to both I hope I haven't drifted away too much from what @Reinmar initially wrote, but it will be good to reconsider different approaches. |
After F2F talk with @Reinmar we concluded that for now we will work to improve the docs so it is more clear which event ( |
I've rewritten those docs completely and we should be fine now. |
According to the clipboard docs which shows the way to preprocess the clipboard data:
and also looking at the clipboard code: https://github.com/ckeditor/ckeditor5-clipboard/blob/c077719bd6cb4acda6301a4966d6c090940d53c2/src/clipboard.js#L145-L178
it seems the intention here is that one can overwrite what's inside data transfer object so it will be pasted inside the editor. However, I am unable to make this work, it seems that native data transfer does not allow changing its data in those scenarios. Check this codepen - https://codepen.io/f1ames/pen/MBNKEo?editors=1010
On Chrome data is not simply changed and on FF it throws
NoModificationAllowedError: Modifications are not allowed for this document
.The text was updated successfully, but these errors were encountered: