-
-
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
Make sure existing picture element is handled correctly on 'sources' downcast #17193
Conversation
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 ); |
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.
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.
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.
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 👍
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 not emptying but removing source elements and inserting new ones (img element should also be reused)
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.
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. |
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 comment looks unrelated to the code. It's a more generic comment about collecting attribute elements and reapplying them.
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.
True, I moved it with the code but it doesn't seem to fit there. Fixed 👍
Suggested merge commit message (convention)
Fix (image): Handle existing picture element correctly on 'sources' downcast. Closes #17192.
Additional information
See #17192.