-
-
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 a space before a block Element in Firefox will replace it with @@
#5651
Comments
Hi! Sorry for the late response. Can you share detailed steps on how to reproduce it in CKEditor 5 with recorded screencast? |
Sure thing. I've set up an example editor build here. If you clone the repository and run
and open the generated Try typing in some text and click the button when the caret is positioned after the text. It should insert a If you move the caret to the end of the text and insert a space, the container is removed and replaced with However (in my example) you can observe a different behavior, when you change the schema in the In chrome both cases work just fine. |
Thanks for a detailed description and live sample! I can confirm this behaviour. @jodator, can you investigate it? |
It's a bit similar to #5613 & #1049. Basically the elements that act as blocks should be blocks (like image) and they shouldn't be nested in other blocks. If you change your schema to: this.editor.model.schema.register( MODEL_ELEMENT_NAME, {
allowIn: '$root',
isObject: true,
isBlock: true
} ); and you'd use class InsertBlockElementCommand extends Command {
execute() {
this.editor.model.change( writer => {
const modelElement = writer.createElement( MODEL_ELEMENT_NAME );
this.editor.model.insertContent( modelElement, this.editor.model.document.selection );
} );
}
} You'd insert your But this would cause other problems with positions mapping (you could place position inside Bonus: use widget in the editing pipeline (remember to include this.editor.conversion.for( 'editingDowncast' ).elementToElement( {
model: MODEL_ELEMENT_NAME,
view: ( element, writer ) => {
const containerElement = writer.createContainerElement( 'div' );
const imgElement = writer.createEmptyElement( 'img' );
writer.insert( writer.createPositionAt( containerElement, 0 ), imgElement );
writer.setAttribute( 'class', 'image-container', containerElement );
writer.setAttribute( 'src', 'https://upload.wikimedia.org/wikipedia/en/a/a9/Example.jpg', imgElement );
writer.setCustomProperty( 'genericBlockElement', true, containerElement );
return toWidget( containerElement, writer ,{ hasSelectionHandle: true });
}
} ); |
Thanks for the response. However, I am not sure if I am satisfied with it: You're correct that this example yields the same behavior when you do not use nested block elements. However that will no longer be the case if you try to let the image As far as I can tell, moving it out of the paragraph will make the text float around the image, but it becomes impossible to align the image so that it is not at either the very top or very bottom of the paragraph. Also it's kinda odd that my version works fine in Chromium-esque browsers - I actually though putting blocks between texts would be an okay thing to do. |
Closing this since it's very old and likely doesn't need a fix (anymore) |
You need a view-model and DOM that has
[Text, Element]
anywhere with the elementsHTMLElement
conforming todisplay: block
.Moving your caret to the last position within your first Text and appending a space will delete the element and replace it with
@@
.As far as I can tell, this issue comes from Firefox inserting a
<br />
out of nowhere, breaking the CK InjectTypingMutationsHandling module. In it'shandle
method thecontainerChildrenMutated
check will somewhat mistakenly succeed and will result in mutating the model incorrectly due to the unexpected new element.You can observe the differing behavior between Chrome and Firefox with a simple html file and using the inspector of each browser. Placing the caret behind the
t
of the firsttext
and hitting space will insert a new<br />
element.I'm not sure if this is expected behavior from Firefox. Maybe it's worth considering to file an issue there, too.
If you'd like to see this fixed sooner, add a 👍 reaction to this post.
The text was updated successfully, but these errors were encountered: