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

Embed images pasted from Word in Safari #1976

Closed
wants to merge 18 commits into from
Closed

Embed images pasted from Word in Safari #1976

wants to merge 18 commits into from

Conversation

msamsel
Copy link
Contributor

@msamsel msamsel commented May 15, 2018

What is the purpose of this pull request?

Bug fix

Does your PR contain necessary tests?

yes

This PR contains

  • Unit tests
  • Manual tests

What changes did you make?

  • Provide possibility to embed images pasted in safari browser
  • Fix saves blobUrls detected during pasting images from Word and replacing them later asynchronously in editor's content.

Close #1134

Copy link
Member

@Comandeer Comandeer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't get it working with Safari 11.1 (13605.1.33.1.2) or Safari Technology Preview Release 56 (Safari 11.2, WebKit 13606.1.17.2.2) and Microsoft Word 15.34 (170330). The image is not pasted at all.

We're also missing real fixtures for pasting images in Safari, generated from Word.

CHANGES.md Outdated
@@ -17,6 +17,7 @@ Fixed Issues:
* [#1592](https://github.com/ckeditor/ckeditor-dev/issues/1592): [Image Base](https://ckeditor.com/cke4/addon/imagebase) caption is not visible after paste.
* [#620](https://github.com/ckeditor/ckeditor-dev/issues/620): Fixed: [`forcePasteAsPlainText`](https://docs.ckeditor.com/ckeditor4/latest/api/CKEDITOR_config.html#cfg-forcePasteAsPlainText) will be respected when internal and cross-editor pasting happen.
* [#1467](https://github.com/ckeditor/ckeditor-dev/issues/1467): Fixed: [Table Resize](https://ckeditor.com/cke4/addon/tableresize) resizing coursor appearing in middle of merged cell.
* [#1134](https://github.com/ckeditor/ckeditor-dev/issues/1134): Fixed: [Paste from word](https://ckeditor.com/cke4/addon/pastefromword) will embed images in Safari browser.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For browsers the style of changelog is:

[Safari] Fixed: Description of the issue.

Please also note that it's "Paste from Word", not "Paste from word"

@@ -65,14 +65,25 @@
return null;
}

function load( url, callback, getResponseFn ) {
function getCustomResponse( xhr ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't it be better to create one getResponse function that would return appropriate response instead of creating one function for every response type? Especially that now ArrayBuffer is supported only in load method and having one function would enable it everywhere with minimal amount of work.

If not, then at least change the function name to something more appropriate, e.g. getResponseArrayBuffer.

} else if ( typeof filteredData === 'object' ) {
editor.fire( 'lockSnapshot' );
pfwEvtData.dataValue = filteredData.dataValue;
handleBlobs( filteredData.blobUrls, function() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering about time between lockSnapshot and unlockSnapshot. If user could write anything in this time, it could result in broken or at least weird snapshot.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Comandeer, yes it's a drawback of this approach. Another option is to make editor somehow readOnly, but I'm not sure what would be better here. WDYT? Should editor be read only during this paste? Or maybe you have some other solutions which I don't see?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making editor read-only sounds even worse. Let's leave it for now as it shouldn't be so critical issue.

@@ -7,7 +7,7 @@
/* global confirm */

CKEDITOR.plugins.add( 'pastefromword', {
requires: 'clipboard',
requires: 'clipboard,ajax',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it any other way to not require ajax for PfW? It looks a little bit strange. I wonder if FileReader would be an alternative here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've considered using FileTools here. Unfortunately FileTools contains logic responsible for uploading files to the server, there is no methods helping downloading files from given URL, where Ajax has it and only requires to add new file type to support. That's it was chosen here. I could extend FileTools, with new functions, but this seems like new separate task, or hide completely XHR inside PFW and do not rely on Ajax plugin.
Using Ajax seems to be most convenient and time efficient for me.

@mlewand WDYT? Should we require Ajax in PFW or use some solution?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Comandeer what are the downsides of using ajax plugin for this case? Using FileReader just for sake of using it results with more code to worry about.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mlewand it wasn't exactly a downside, I just felt that current use of ajax plugin is inappropriate, but I haven't spend much time on it as whole fix wasn't working for me. You're comment about using plugin in core explains my anxiety ;)

function replaceBlobUrlsInEditor( map ) {
for ( var blob in map ) {
var nodeList = editor.editable().find( 'img[src="' + blob + '"]' ).toArray();
CKEDITOR.tools.array.forEach( nodeList, function( element ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amount of CKEDITOR.tools in handleBlobs is too high. Let's make some short alias, which will increase the readability.

@msamsel
Copy link
Contributor Author

msamsel commented May 28, 2018

I can't get it working with Safari 11.1 (13605.1.33.1.2) or Safari Technology Preview Release 56 (Safari 11.2, WebKit 13606.1.17.2.2) and Microsoft Word 15.34 (170330). The image is not pasted at all.

I test it on Safari 11.1 (13605.1.33.1.4) and MS Word 15.41 (171205) MacOS HighSierra (10.13.4) and it is working completely fine. Maybe you have some strange picture which is not embed as blobUrl by Safari? Could you provide your docx file?

We're also missing real fixtures for pasting images in Safari, generated from Word.

What do you have on your mind by "real fixtures". Do you want just to have soem real markup in test or you think about integrating it with generated tests? In case of 2nd option, it would require tremendous amount of work to adapt generated test to work with Safari fixtures:

@Comandeer
Copy link
Member

Word document with image – not working with Safari 11.1 (13605.1.33.1.4). I tried every single method of inserting image (pasting, via menu, d&d…), nothing works.

@Comandeer
Copy link
Member

Uh, after update of Word to 16.13.1 (180523) it started working.

core/tools.js Outdated
*/

convertBlobUrlToBase64: function( blobUrlSrc, callback ) {
CKEDITOR.ajax.load( blobUrlSrc, function( arrayBuffer ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ajax plugin function can not be used in core, since it's not guaranteed it's going to be there. If anything the logic should go to the ajax plugin itself.

@Comandeer
Copy link
Member

Taking over this PR!

@Comandeer
Copy link
Member

I modified handling snapshots as the last version seemed to disable undo.

@Comandeer Comandeer requested a review from mlewand June 1, 2018 12:16
@Comandeer Comandeer dismissed their stale review June 1, 2018 12:17

Taken over PR.

@f1ames f1ames added the pr:frozen ❄ The pull request on which work was suspended due to various reasons. label Jan 16, 2020
@f1ames f1ames closed this Jan 16, 2020
Comandeer added a commit that referenced this pull request Oct 19, 2020
Comandeer added a commit that referenced this pull request Oct 19, 2020
Comandeer added a commit that referenced this pull request Nov 16, 2020
Comandeer added a commit that referenced this pull request Nov 16, 2020
jacekbogdanski pushed a commit that referenced this pull request Nov 23, 2020
jacekbogdanski pushed a commit that referenced this pull request Nov 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr:frozen ❄ The pull request on which work was suspended due to various reasons.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Integration PFW Image with Safari
4 participants