-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -178,6 +178,19 @@ export class RichTextData { | |
} | ||
} | ||
|
||
for ( const name of Object.getOwnPropertyNames( String.prototype ) ) { | ||
if ( RichTextData.prototype.hasOwnProperty( name ) ) { | ||
continue; | ||
} | ||
|
||
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 commentThe 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 commentThe 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. |
||
}, | ||
} ); | ||
} | ||
|
||
/** | ||
* Create a RichText value from an `Element` tree (DOM), an HTML string or a | ||
* plain text string, with optionally a `Range` object to set the selection. If | ||
|
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.