-
-
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
#8659: Implemented pasting/dropping heuristics to better recognize user's intention #9351
Conversation
…ge style manual test.
…ImageBlockEditing.
👍 That was my thought as well. I agree with the other scenarios too. |
…id of repeating code.
…eality the cases are handled as a paste.
TODO: https://github.com/ckeditor/ckeditor5/pull/9352/files could benefit from |
export function isInlineViewImage( element ) { | ||
return !!element && element.is( 'element', 'img' ); | ||
} |
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.
This util is very generic so I can image cases when someone would use it on the img
element inside a figure
and it would give an invalid result. Maybe we should check if this element's parent is not a figure?
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.
Also, I'm not sure about the name of this util, maybe isInlineImageView()
would be better? Same for isBlockViewImage()
-> isBlockImageView()
.
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.
This util is very generic so I can image cases when someone would use it on the
img
element inside afigure
and it would give an invalid result. Maybe we should check if this element's parent is not a figure?
TBH I don't see anything wrong with using it for the inner structure of a block widget; it already happens in this PR in getViewImageFromWidget()
.
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.
👍
export function determineImageTypeForInsertionAtSelection( editor, selection ) { | ||
const schema = editor.model.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.
Maybe we could pass schema
in params instead of the whole editor
?
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.
Also, this is missing the editor.config.get( 'image.insert.type' )
to allow forcing default image type on insertion.
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.
Also, this is missing the
editor.config.get( 'image.insert.type' )
to allow forcing default image type on insertion.
I'm not sure whether this tool should respect this configuration.
When used in insertImage()
, some other logic handles this configuration and that's OK.
If we're going to use it in the clipboard pipeline, though, this would be partially against the module:image/imageinsert~ImageInsertConfig#type
documentation which states it works for new images only. And since we have no means to discover whether a pasted image is returning back to the same editor or comes from an external data source, I'd rather not use it here. This way copy/paste inside the editor will be at least more predictable.
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.
👍
Co-authored-by: Kuba Niegowski <1232187+niegowski@users.noreply.github.com>
Co-authored-by: Kuba Niegowski <1232187+niegowski@users.noreply.github.com>
Co-authored-by: Kuba Niegowski <1232187+niegowski@users.noreply.github.com>
Co-authored-by: Kuba Niegowski <1232187+niegowski@users.noreply.github.com>
Co-authored-by: Kuba Niegowski <1232187+niegowski@users.noreply.github.com>
Co-authored-by: Kuba Niegowski <1232187+niegowski@users.noreply.github.com>
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.
👍 LGTM except for the failing tests in the link package.
Fixed. |
Suggested merge commit message (convention)
Internal (image): Implemented pasting/dropping heuristics to better recognize the user's intention. Closes #8659. Closes #9344.
In this branch, I propose the following heuristics for both internal and external paste/drop:
Pasting an inline image into an empty block or over an existing block (widget)
I assume the intent is to make the image block if pasted/dropped in this place and the image type is changed.
Pasting a captionless block image into a paragraph (block)
I see no good reason why the image should break the paragraph. For one thing, it is surprising. Also, if the paragraph was broken, this would be a costly operation from the UX standpoint to put things back together (undo or manual backspacing). IMO in my approach, the user gets better UX at virtually no cost.
Pasting a block image with a caption into a paragraph (block)
I didn't change anything in this scenario because:
cke-data-caption
) during paste to preserve the caption content in the upcast and store it in thecaption
model attribute (that we already have) so it can be reverted on demand,