-
Notifications
You must be signed in to change notification settings - Fork 37
t/225: The ImageUploadCommand should check whether it can be executed in the selection context. #228
Conversation
…n the selection context.
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 not 100% sure why there's parent swapping before checking. Maybe some method would be better?
const position = selection.getFirstPosition(); | ||
let parent = position.parent; | ||
|
||
if ( parent != parent.root ) { |
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 missing a comment why this check and parent swapping.
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.
ps.: Also this doesn't look consistent as it might swap to:
- blockQuote (from p, h1, l1, etc inside blockquote)
- tableRow (from tableCell) - I'm not sure what should be there (table/tableCell - oncoming block content in table cell)
- $root (from p, h1, l1, etc)
Maybe it should lookup for allowed parent or something other in the schema?
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.
ps.: A comment would be sufficient also :)
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.
TBH, I copy&pasted it from the InsertTableCommand
implementation without any deeper analysis. The upload command never splits the block, it inserts the new image next to the one the selection is anchored to. So I guess the if
is correct here because it comes down to
get the first ancestor of the current block, unless it's the root
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.
BTW, have you seen https://github.com/ckeditor/ckeditor5-image/issues/225#issuecomment-407021363? Do you have any idea how to include a fix for that without breaking the multi-upload?
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'll check that and let you know :)
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.
@oleq Sorry for longer reply. So I've manage to make #227 work by adding multi-file upload support to the FileUploadCommand
itself:
// Extend current behavior of uploading one file
const filesToUpload = Array.isArray( options ) ? options : [ options ];
for ( const { file, insertAt } of filesToUpload ) {
uploadImage( editor, fileRepository, file, insertAt, doc );
}
Where uploadImage()
is the method that previously uploaded a file (contents of editor.model.change
block.
This way the command can be disabled when an image is selected but it will allow UI to pass multiple files to upload at once - not as it is currently where each file is processed individually by a command. The problem is that after execute()
the first image is selected and the command itself was disabled so next files were discarded as the command goes disabled then.
I have no other idea for solving this as probably the expected behavior is to select newly inserted image.
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.
ps.: the ImageUploadUI
was modified to:
view.on( 'done', ( evt, files ) => {
const toUpload = [];
for ( const file of Array.from( files ) ) {
const insertAt = findOptimalInsertionPosition( editor.model.document.selection );
if ( isImageType( file ) ) {
toUpload.push( { file, insertAt } );
}
}
editor.execute( 'imageUpload', toUpload );
} );
but those two snippets must be checked if there are OK as the files are inserted in revers order (AFAICS).
@pjasiun please review this changes. The goal was to disable the image button in table (works) and also not break multiple images upload. What I'm not sure about is the naming of the |
So:
|
I'm not sure if I follow this correctly but:
I think that we should check two things:
|
…e the optimal position to inserting images.
@pjasiun: I've updated the PR with your comments and also I've been able to address issues from #227 & #235. |
I am not sure about "2". I think it should be more generic and consider all objects. I see no difference between uploading an image when image or media is selected. One idea is that if the selection is over an object we check in the schema if this object can contain the image. On the other hand, we can assume that an object can not be a parent of the image (it does not seem to make much sense) and disable image upload whenever an object is selected. |
I think that the |
I think it should be consistent: if you are able to insert image when selection is like this, then the command/button should be available. If the button is disabled it should mean that you are not able to execute the command with such a position (it does nothing). Both ways are fine for me, but I think we should not disable button on the selection which works for executing the command. |
One "tiny" problem – the command accepts That's a big problem that I think I discussed with @oskarwrobel in the past. Honestly, I don't know how to fix this situation. We've been discussing that
|
I can see you partly agree with that in https://github.com/ckeditor/ckeditor5-image/issues/235. So it's a matter of cleaning up |
Yes and yes.
I would go with all objects. |
…adEditing` will use `ImageUploadCommand` for uploading pasted images.
@pjasiun Ready to re-review after latest comments. |
|
||
// Additional check for when the command should be disabled: | ||
// - selection is on image | ||
// - selection is inside image (image caption) |
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.
Comment need to be updated.
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.
You can close the ticket as soon as you update comments mentioned above.
Suggested merge commit message (convention)
Fix: The
ImageUploadCommand
should check whether it can be executed in the selection context. Closes ckeditor/ckeditor5#5158. Closes ckeditor/ckeditor5#5160. Closes ckeditor/ckeditor5#5163.BREAKING CHANGE: The
options.file
property was renamed tooptions.files
for'imageUpload'
command.BREAKING CHANGE: The
options.insertAt
property for'imageUpload'
command was removed. The command will use model's selection.