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
TINY-10854: Now insert format also manage nbsp
s correctly
#9636
base: main
Are you sure you want to change the base?
Conversation
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.
- Fix typos in PR title npsp -> nbsp and correclty -> correctly
npsp
s correcltynbsp
s correctly
@@ -0,0 +1,6 @@ | |||
project: tinymce | |||
kind: Fixed | |||
body: 'Extra unnecessary nbsp entities was inserted before and after inline elements created by input of formatted text.' |
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.
body: 'Extra unnecessary nbsp entities was inserted before and after inline elements created by input of formatted text.' | |
body: Unnecessary nbsp entities were inserted when typing at the edges of inline elements. |
|
||
const normalizeNbspsBetween = (editor: Editor, caretContainer: Node | null) => { | ||
const handler = () => { | ||
if (caretContainer && !editor.dom.isEmpty(caretContainer)) { |
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.
I'm surprised that removing every nbsp passes the tests. But our tests for NBSP normalisation probably don't cover this new caretContainer
condition well enough. Speaking of which...
if (caretContainer && !editor.dom.isEmpty(caretContainer)) { | |
if (caretContainer !== null && !editor.dom.isEmpty(caretContainer)) { |
Try something like <p>text <strong> more text</strong></p>
. Your code will probably remove the nbsp, which is wrong.
- do some wider checks of this logic
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.
ok, I'm writing the logic for it, I'd like to make an abstraction starting from Nbsps.ts to use it in both cases, but I'm not sure how possible is since it's strong relation with the elements of the DOM.
Since the logic in Nbsps.ts
isn't working for this cases, what logic do we want to implement?
by now we have these tests: NbspsTest.ts, should I make these cases work considering that instead of a simple text that could be an inline 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.
I would break out the everything inside the isEmpty check. Then make a separate function that takes a target node that checks the sibling before target, first child of target, last child of target, sibling after target. Then checks if any of those nodes has a non whitespace character followed by a nbsp since then you can replace that nbsp with a space.
Maybe feed those siblings into an array if that makes things easier. We might need to expand this in the future for other cases like <strong>foo <span>bar</span>
etc.
Maybe it makes sense to stick that new function into the Nbsps module?
|
||
const normalizeNbspsBetween = (editor: Editor, caretContainer: Node | null) => { | ||
const handler = () => { | ||
if (caretContainer && !editor.dom.isEmpty(caretContainer)) { |
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.
I would break out the everything inside the isEmpty check. Then make a separate function that takes a target node that checks the sibling before target, first child of target, last child of target, sibling after target. Then checks if any of those nodes has a non whitespace character followed by a nbsp since then you can replace that nbsp with a space.
Maybe feed those siblings into an array if that makes things easier. We might need to expand this in the future for other cases like <strong>foo <span>bar</span>
etc.
Maybe it makes sense to stick that new function into the Nbsps module?
Related Ticket: TINY-10854
Description of Changes:
Since to normalize the
nbsp
s we use normalizeNbsps but this mechanism is based on the text elements and to fix our case we would need to find the parent and parse all the children element which could require way more time.Since when we add a format we apply a CaretFormat, so to fix this case my idea is to apply an
nbsp
normalization with oninput
(like fornormalizeNbspsInEditor
in InputKeys), but only for the next insertion (so usingeditor.once
) since this is needed only after the first insertion.Pre-checks:
feature/
,hotfix/
orspike/
Review:
Docs ticket created (if applicable)GitHub issues (if applicable):