fix: Pasting rich text into image caption inherits styling

This commit is contained in:
Tom Moor
2023-07-11 21:28:38 -04:00
parent a9ab196a18
commit 5c83070941

View File

@@ -215,6 +215,14 @@ export default class Image extends SimpleImage {
void downloadImageNode(node); void downloadImageNode(node);
}; };
// Ensure only plain text can be pasted into input when pasting from another
// rich text source.
handlePaste = (event: React.ClipboardEvent<HTMLSpanElement>) => {
event.preventDefault();
const text = event.clipboardData.getData("text/plain");
window.document.execCommand("insertText", false, text);
};
component = (props: ComponentProps) => ( component = (props: ComponentProps) => (
<ImageComponent <ImageComponent
{...props} {...props}
@@ -223,6 +231,7 @@ export default class Image extends SimpleImage {
onChangeSize={this.handleChangeSize(props)} onChangeSize={this.handleChangeSize(props)}
> >
<Caption <Caption
onPaste={this.handlePaste}
onKeyDown={this.handleKeyDown(props)} onKeyDown={this.handleKeyDown(props)}
onBlur={this.handleBlur(props)} onBlur={this.handleBlur(props)}
onMouseDown={this.handleMouseDown} onMouseDown={this.handleMouseDown}