-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Conversation
There was a problem hiding this 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. |
There was a problem hiding this comment.
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"
plugins/ajax/plugin.js
Outdated
@@ -65,14 +65,25 @@ | |||
return null; | |||
} | |||
|
|||
function load( url, callback, getResponseFn ) { | |||
function getCustomResponse( xhr ) { |
There was a problem hiding this comment.
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
.
plugins/pastefromword/plugin.js
Outdated
} else if ( typeof filteredData === 'object' ) { | ||
editor.fire( 'lockSnapshot' ); | ||
pfwEvtData.dataValue = filteredData.dataValue; | ||
handleBlobs( filteredData.blobUrls, function() { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ;)
plugins/pastefromword/plugin.js
Outdated
function replaceBlobUrlsInEditor( map ) { | ||
for ( var blob in map ) { | ||
var nodeList = editor.editable().find( 'img[src="' + blob + '"]' ).toArray(); | ||
CKEDITOR.tools.array.forEach( nodeList, function( element ) { |
There was a problem hiding this comment.
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.
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?
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:
|
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. |
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 ) { |
There was a problem hiding this comment.
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.
Taking over this PR! |
… to be full asynchronous.
…tion to handleBlob function.
I modified handling snapshots as the last version seemed to disable undo. |
What is the purpose of this pull request?
Bug fix
Does your PR contain necessary tests?
yes
This PR contains
What changes did you make?
Close #1134