New composer: support pasting files

This commit is contained in:
Bruno Windels 2019-08-29 16:19:05 +02:00
parent 599fccd9ce
commit fe7ac11abc
2 changed files with 23 additions and 0 deletions

View file

@ -309,6 +309,10 @@ export default class BasicMessageEditor extends React.Component {
} }
} }
getEditableRootNode() {
return this._editorRef;
}
isModified() { isModified() {
return this._modifiedFlag; return this._modifiedFlag;
} }

View file

@ -32,6 +32,7 @@ import {processCommandInput} from '../../../SlashCommands';
import sdk from '../../../index'; import sdk from '../../../index';
import Modal from '../../../Modal'; import Modal from '../../../Modal';
import { _t } from '../../../languageHandler'; import { _t } from '../../../languageHandler';
import ContentMessages from '../../../ContentMessages';
function addReplyToMessageContent(content, repliedToEvent, permalinkCreator) { function addReplyToMessageContent(content, repliedToEvent, permalinkCreator) {
const replyContent = ReplyThread.makeReplyMixIn(repliedToEvent); const replyContent = ReplyThread.makeReplyMixIn(repliedToEvent);
@ -226,8 +227,13 @@ export default class SendMessageComposer extends React.Component {
this._clearStoredEditorState(); this._clearStoredEditorState();
} }
componentDidMount() {
this._editorRef.getEditableRootNode().addEventListener("paste", this._onPaste, true);
}
componentWillUnmount() { componentWillUnmount() {
dis.unregister(this.dispatcherRef); dis.unregister(this.dispatcherRef);
this._editorRef.getEditableRootNode().removeEventListener("paste", this._onPaste, true);
} }
componentWillMount() { componentWillMount() {
@ -310,6 +316,19 @@ export default class SendMessageComposer extends React.Component {
this._editorRef && this._editorRef.focus(); this._editorRef && this._editorRef.focus();
} }
_onPaste = (event) => {
const {clipboardData} = event;
if (clipboardData.files.length) {
// This actually not so much for 'files' as such (at time of writing
// neither chrome nor firefox let you paste a plain file copied
// from Finder) but more images copied from a different website
// / word processor etc.
ContentMessages.sharedInstance().sendContentListToRoom(
Array.from(clipboardData.files), this.props.room.roomId, this.context.matrixClient,
);
}
}
render() { render() {
return ( return (
<div className="mx_SendMessageComposer" onClick={this.focusComposer} onKeyDown={this._onKeyDown}> <div className="mx_SendMessageComposer" onClick={this.focusComposer} onKeyDown={this._onKeyDown}>