-
-
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
Inserting (pasting/uploading) an image into an empty list item should make it inline #9391
Comments
What about table? this shouldn`t act the same? |
I guess to apply the fix properly to resolve the issue is to update the ckeditor5/packages/ckeditor5-image/src/image/utils.js Lines 94 to 98 in 0cb8e4c
As for now, the After a few modifications, I can insert the inline image to an empty list item: export function determineImageTypeForInsertionAtSelection( schema, selection ) {
const firstBlock = first( selection.getSelectedBlocks() );
if ( !firstBlock ) {
return 'image';
}
if ( firstBlock.isEmpty ) {
if ( firstBlock.name === 'listItem' /* || firstBlock.name === 'tableCell' */ ) {
return 'imageInline';
}
return 'image';
}
return schema.isObject( firstBlock ) ? 'image' : 'imageInline';
} However, I am unsure about this solution. What about mentioned the Let's consider two cases: The first one is about inserting inline images by default into the elements that accept export function determineImageTypeForInsertionAtSelection( schema, selection ) {
const firstBlock = first( selection.getSelectedBlocks() );
// Insert the `image` element if selected any object.
if ( !firstBlock || schema.isObject( firstBlock ) ) {
return 'image';
}
// Otherwise, check whether the text is allowed in the element. If so, insert an inline image by default.
return schema.checkChild( firstBlock, '$text') ? 'imageInline' : 'image';
} The second one is about exposing the configuration array with names of elements where the inline image should be inserted by default. const config = {
image: {
// Yeah, Java style.
nameOfElementsWithInlineImages: [
'listItem',
'tableCell',
// and more...?
]
}
};
export function determineImageTypeForInsertionAtSelection( schema, selection ) {
const firstBlock = first( selection.getSelectedBlocks() );
if ( !firstBlock ) {
return 'image';
}
if ( firstBlock.isEmpty ) {
return nameOfElementsWithInlineImages.includes( firstBlock.name ) ? 'imageInline' : 'image';
}
return schema.isObject( firstBlock ) ? 'image' : 'imageInline';
} As for now, I cannot recall more elements that should insert inline images by default. Maybe I should not complicate the problem and apply the 1st proposition. WDYT? |
This would break the UX that we want to insert block images into an empty block.
If we would like to implement this approach then this should be registered from the list feature, not the configuration.
The table cells should not be our concern, inserting an image is not affecting the table structure (it's not replacing a table cell with a block image).
This one bugs me the most, but OTOH current lists behave this way when there is no inline images support or it's simply disabled so maybe we should go with the simplest hardcoded way at last for now. |
Other (image): When inserting an image in an empty list item, the `inlineImage` element will be used as the default type of image. Closes #9391.
Closed in #9606. |
📝 Provide a description of the improvement
...unless the pasted image is a block that has a caption already.
This optimization will preserve the structure of lists, which is pretty fragile and gets easily destroyed when a block image splits it in half.
A follow-up of #9102 and #8659.
If you'd like to see this improvement implemented, add a 👍 reaction to this post.
The text was updated successfully, but these errors were encountered: