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

#8659: Implemented pasting/dropping heuristics to better recognize user's intention #9351

Merged
merged 26 commits into from
Apr 7, 2021

Conversation

oleq
Copy link
Member

@oleq oleq commented Mar 24, 2021

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:

  • if there is a caption, they probably meant to have it, and converting into an inline image would mean getting rid of it,
    • that would be a surprise,
  • if we really got rid of the caption, we'd need some indicator, for instance, a hint pinned to the "toggle caption" button and/or a toast notification to let the user know they can see the caption and it wasn't lost,
    • at this moment we don't have resources to implement either of the systems,
    • we'd also need to implement the view figcaption -> view img attribute transition (for instance cke-data-caption) during paste to preserve the caption content in the upcast and store it in the caption model attribute (that we already have) so it can be reverted on demand,
      • that's another layer of complexity we don't need right now

@Reinmar
Copy link
Member

Reinmar commented Mar 24, 2021

if there is a caption, they probably meant to have it, and converting into an inline image would mean getting rid of it,

  • that would be a surprise,

👍 That was my thought as well.

I agree with the other scenarios too.

@oleq oleq marked this pull request as ready for review March 26, 2021 12:54
@oleq oleq requested a review from niegowski March 26, 2021 12:54
@oleq
Copy link
Member Author

oleq commented Mar 30, 2021

TODO: https://github.com/ckeditor/ckeditor5/pull/9352/files could benefit from isBlockViewImage introduced in this PR. If that PR lands first, let's align the code to new helper.

Comment on lines 123 to 125
export function isInlineViewImage( element ) {
return !!element && element.is( 'element', 'img' );
}
Copy link
Contributor

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?

Copy link
Contributor

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().

Copy link
Member Author

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?

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().

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Comment on lines 299 to 300
export function determineImageTypeForInsertionAtSelection( editor, selection ) {
const schema = editor.model.schema;
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

packages/ckeditor5-image/src/image/imageblockediting.js Outdated Show resolved Hide resolved
packages/ckeditor5-image/src/image/imageblockediting.js Outdated Show resolved Hide resolved
packages/ckeditor5-image/src/image/imageblockediting.js Outdated Show resolved Hide resolved
packages/ckeditor5-image/tests/image/imageinlineediting.js Outdated Show resolved Hide resolved
packages/ckeditor5-image/tests/image/imageinlineediting.js Outdated Show resolved Hide resolved
packages/ckeditor5-image/tests/image/imageinlineediting.js Outdated Show resolved Hide resolved
packages/ckeditor5-image/tests/image/imageinlineediting.js Outdated Show resolved Hide resolved
packages/ckeditor5-image/tests/image/utils.js Outdated Show resolved Hide resolved
oleq and others added 15 commits April 1, 2021 11:49
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>
@oleq oleq requested a review from niegowski April 6, 2021 13:40
Copy link
Contributor

@niegowski niegowski left a 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.

@oleq
Copy link
Member Author

oleq commented Apr 6, 2021

👍 LGTM except for the failing tests in the link package.

Fixed.

@oleq oleq merged commit df3cff5 into i/2052-inline-images Apr 7, 2021
@oleq oleq deleted the i/8659-clipboard-improvements branch April 7, 2021 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants