-
-
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
Cannot type after inserting break line element in a paragraph that ends with a space #1024
Comments
Some debug notes:
function hasOnlyTextNodes( children ) {
return children.every( child => child.is( 'text' ) || child.is( 'element', 'break' ) );
} The mutation wasn't ignored but the letter was inserted in invalid place: I assume that the comment:
should be somehow fixed. |
May be related to #692. |
That's a first thing to check. Why typing a letter causes a children mutation, not a text node mutation. You need to check the native mutations to see what they contain. There's a chance that this is really a children mutation and will need to be handled by us. But it's also possible that due to issues mentioned in #692 we incorrectly discover this mutation as a children mutation. |
Let's start with the editor that contains: <p>Paragraph 1 <br>[]</p>
<p>Paragraph 2</p> After pressing the letter ( domMutations.length // 1
domMutations[ 0 ] instanceof MutationRecord // true
domMutations[ 0 ].addedNodes // NodeList (empty)
domMutations[ 0 ].attributeName // null
domMutations[ 0 ].attributeNamespace // null
domMutations[ 0 ].oldValue // ""
domMutations[ 0 ].removedNodes // (empty)
domMutations[ 0 ].type // "characterData"
domMutations[ 0 ].target // Text "​​​​​​​a" In L174 of the same file, we're trying to find corresponding view text but it fails and the mutation is tracked as We even have a comment that describes what happened (some lines later): // When we added first letter to the text node which had only inline filler, for the DOM it is mutation
// on text, but for the view, where filler text node did not existed, new text node was created, so we
// need to fire 'children' mutation instead of 'text'. |
Hehe :) Nice! So you were right about this:
Inline elements need to be handled by this function. We could change this to:
This will be enough for now. |
I've just realised – why does it happen only when there's a space at the end of the previous line? If the issue was (only) in And there are is one more issue here. I think it may be related. Space after (or before) <p>XX<br> Y</p> It's only rendered as long as there's selection in the Spaces around This algorithm is controlled by |
One more case to check:
A space after |
I don't understand what do you mean by this case. But I've just noticed that sometimes we render <p>XX <br>[]YY</p> It will become: <p>XX <br> []YY</p> However, if you'd start with this: <p>XX<br>[]YY</p> We'd render: <p>XX<br> []YY</p> So, there's certainly something wrong there. I guess that that algorithm skips |
PS. When testing this manually, make sure that there's no inline filler rendered because it will give you different visual results. You must be looking at a clean DOM. |
Just to be sure where we need to render <div contenteditable>
<p>XX <br>YY</p>
<p>XX <br>YY</p>
<p>XX<br> YY</p>
<p>XX<br> YY</p>
</div> (see: https://jsfiddle.net/zh51rd9s/) The first two paragraphs are ok. You can place the caret at Regarding cases 3 and 4 we can see that we need to render |
Fixing view to DOM conversion wasn't hard. Spaces touching DOM to view conversion is also broken and it's more tricky due to how it's implemented now. We use the const treeWalker = document.createTreeWalker( topmostParent, NodeFilter.SHOW_TEXT ); So it only cares for text nodes, ignoring everything on the way to them. Then, it only checks the common ancestors. Naturally, in such a case: <p>foo<br>bar</p> when we're processing the <p><b><i>foo</i></b><br>bar</p> We can't implement a simple check like |
BTW, I'm talking about "significant inline nodes" because I have a feeling that it's not only about Alternatively, if we're focused on |
Fix: Fixed view <-> DOM conversion of whitespaces around `<br>` elements. Closes ckeditor/ckeditor5#1024.
@Reinmar: Ugh.. so simple fix: should be changed to (to allow function isSafeForTextMutation( children ) {
return children.every( child => child.is( 'text' ) || child.is( 'softBreak' ) || child.is( 'placeholder' ) );
} Now I havn't tested this yet but I'm pretty sure that this cannot be As for the solution I tend to creating either:
As on the API updates needed there must be some additions at least so either solution looks OK. |
Is this a bug report or feature request? (choose one)
🐞 Bug report
💻 Version of CKEditor
Latest
master
in all packages.📋 Steps to reproduce
During work on
ShiftEnter
(soft enter, soft return) plugin, I noticed that you cannot type after inserting a<br>
directly after space.The
ShiftEnter
plugin is on the review (ckeditor/ckeditor5-enter#54), but the PR comes from the community. Instead of cloning the new repo and linking everything, I decided to copy the changes to the new branch that speed up reproducing the issue.ckeditor5-engine
package.npm run test:manual -- --files=enter
)✅ Expected result
MT defines two helpers:
After reproducing the steps above, the functions should return:
❎ Actual result
But they return:
📃 Other details that might be useful
The same thing will happen in image caption but the
<br>
element will not be visible in the editor but occurs in the DOM.The text was updated successfully, but these errors were encountered: