-
-
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
Hello, when using the ckeditor5, I want to add <P><br/></p> after inserting the picture format. I don't know how to do that. #1255
Comments
Hi, @gongzhiq! I've answered this question on SO - https://stackoverflow.com/a/52442482/2043175 - is that yours? Basically, I was able to listen to the model changes, iterate over last changes and insert an empty paragraph before every image. const model = editor.model;
const doc = editor.model.document;
doc.on( 'change:data', () => {
const changes = doc.differ.getChanges();
model.change( writer => {
for ( const entry of changes ) {
if ( entry.type == 'insert' && entry.name == 'image' ) {
const image = entry.position.nodeAfter;
const paragraph = writer.createElement( 'paragraph' );
writer.insert( paragraph, image, 'before' );
}
}
} );
} ); As I mentioned on the SO, the current implementation inserts a paragraph before each image. |
You mean that this: writer.insert( paragraph, image1, 'after' );
/*
<image1></image1>
<image2></image2>
<image3></image3>
*/ Inserts the paragraph after |
Oh, now I see. Images are inserted one by one. So this is what happens:
And so on... I was surprised that iterating over changes in the other direction doesn't solve the problem and now I know why. |
You mean – when you drop multiple images at once? Yep, they are inserted one by one. BTW, I think the above code should use a post-fixer. I didn't notice you listen on |
This is still tricky and the result is the same as using const model = editor.model;
const doc = editor.model.document;
const root = doc.getRoot();
doc.registerPostFixer( writer => {
// Iterate from the end ato preserve correct positions.
for ( let i = root.childCount -1 ; i--; i >= 1 ) {
if ( root.getChild( i ).name === 'image' && root.getChild( i - 1 ).name === 'image' ) {
const paragraph = writer.createElement( 'paragraph' );
writer.insert( paragraph, root.getChild( i - 1 ), 'after' );
}
}
} ); |
Aaa!!! There's a bug in cc @pjasiun |
I cced you, @pjasiun, because I think there was some issue with that piece of code in the past: Do you remember whether we used multiple change blocks on purpose? |
It also duplicates the |
For sure using multiple Anyway, as @jodator mentioned we will change it soon, so the upload command will be able to handle multiple images what means that the whole action will be executed in a single change block. |
Great to hear it. So once the PR is merged I'll update the snippet for this question. |
@pjasiun no. The |
@gongzhiq, note that to create an empty paragraph manually after the image you can use Enter when the image is selected. Similarly to create a paragraph before the image (if it's the first element in document) you can press Shift + Enter. This is a temporary solution, you can read more in #407. I'm not sure if you know it, that's something I might overlook. |
So I believe it should be changed. |
I also believe in it. More so I think it must be changed :) |
Thank you. Many good suggestions have been given. |
@
Inserts the paragraph after |
modify imageinsertcommand.js
|
There has been no activity on this issue for the past two years. We've marked it as stale and will close it in 30 days. We understand it may be relevant, so if you're interested in the solution, leave a comment or reaction under this issue. |
There has been no activity on this issue for the past year. We've marked it as stale and will close it in 30 days. We understand it may still be relevant, so if you're interested in the solution, leave a comment or reaction under this issue. |
We've closed your issue due to inactivity over the last year. We understand that the issue may still be relevant. If so, feel free to open a new one (and link this issue to it). |
Hello, when using the ckeditor5, I want to add
<P><br/></p>
after inserting the picture format. I don't know how to do that.Now, insert the image in the format:
<figure class="image ck-widget">
<img src="">
<figcaption class="ck-editor__editable ck-editor__nested-editable">dsfa</figcaption>
</figure>
The format I want is:
<figure class="image ck-widget">
<img src="">
<figcaption class="ck-editor__editable ck-editor__nested-editable">dsfa</figcaption>
</figure>
<P><br/></p>
How to insert
<P><br/></p>
after figureLike this
The text was updated successfully, but these errors were encountered: