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

Make sure existing picture element is handled correctly on 'sources' downcast #17193

Merged
merged 2 commits into from
Oct 17, 2024

Conversation

f1ames
Copy link
Contributor

@f1ames f1ames commented Oct 1, 2024

Suggested merge commit message (convention)

Fix (image): Handle existing picture element correctly on 'sources' downcast. Closes #17192.


Additional information

See #17192.

@DawidKossowski DawidKossowski changed the title Make sure existing picture element is handled correctly on 'sources' downcast. Make sure existing picture element is handled correctly on 'sources' downcast Oct 14, 2024
Comment on lines 254 to 258
if ( prevPictureElement ) {
// Insert a new picture, move img into it, remove previous picture element (ckeditor5#17192).
viewWriter.insert( viewWriter.createPositionBefore( prevPictureElement ), pictureElement );
viewWriter.move( viewWriter.createRangeOn( imgElement ), viewWriter.createPositionAt( pictureElement, 'end' ) );
viewWriter.remove( prevPictureElement );
Copy link
Contributor

Choose a reason for hiding this comment

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

What would happen if other converters downcast other attributes to the picture element? Would those be lost? Maybe in such a case, we should remove source elements from the picture element and reinsert them into the already existing picture element.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point 👍 🤔 So you basically mean to reuse existing picture element by emptying it and adding new elements inside it instead of recreating the whole structure AFAIU. I'll adjust the code then 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe not emptying but removing source elements and inserting new ones (img element should also be reused)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 893b1e3 and even the code go slightly simpler 👍 I had to add a custom attribute handling in test because we don't have anything for picture from what I see.


viewWriter.remove( viewWriter.createRangeIn( pictureElement ) );

// Make sure <picture> does not break attribute elements, for instance <a> in linked images.
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment looks unrelated to the code. It's a more generic comment about collecting attribute elements and reapplying them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True, I moved it with the code but it doesn't seem to fit there. Fixed 👍

@f1ames f1ames merged commit 6257c78 into master Oct 17, 2024
10 checks passed
@f1ames f1ames deleted the ck/17192 branch October 17, 2024 12:10
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.

Picture "sources" downcast converter duplicates "picture" element when "sources" model attribute updated
2 participants