-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Rich text: add HTML string methods to RichTextData #57322
Conversation
Size Change: +49 B (0%) Total Size: 1.71 MB
ℹ️ View Unchanged
|
Object.defineProperty( RichTextData.prototype, name, { | ||
value( ...args ) { | ||
// Should we convert back to RichTextData? | ||
return this.toHTMLString()[ name ]( ...args ); |
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 think it would be great if we convert back to RichTextData here, but I'm not sure. One downside would be that you'd be parsing and serialising every time you use one of these methods.
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.
In the future, should also warn when using these methods, but not until we have alternative methods available.
@@ -178,6 +178,19 @@ export class RichTextData { | |||
} | |||
} | |||
|
|||
for ( const name of Object.getOwnPropertyNames( String.prototype ) ) { |
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.
Do you think converting all methods like that is good? I mean, there's a huge chance that most these methods will create sync issues between the string and the object no? Maybe we should convert case by case.
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.
What do you mean with sync issues? Sure, I can hardcode the list here instead if you prefer.
What?
This is meant to prevent errors when people use string methods on the rich text value and so things keep working as expected for back compat. Previously these values were plain strings with HTML.
Why?
See #57093, and other third party instances with errors.
How?
We just add all the string methods to the class prototype.
Extending String is not an option because we'd have to pre-serialise the HTML when initialising the instance.
Testing Instructions
There's probably a few way to test, but here what I did:
Testing Instructions for Keyboard
Screenshots or screencast