Skip to content

Commit

Permalink
Fixed pasting images not working
Browse files Browse the repository at this point in the history
  • Loading branch information
hmhealey committed Apr 4, 2017
1 parent c4fd04e commit aa92ac8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
6 changes: 6 additions & 0 deletions webapp/components/create_comment.jsx
Expand Up @@ -51,6 +51,7 @@ export default class CreateComment extends React.Component {
this.handleUploadError = this.handleUploadError.bind(this);
this.removePreview = this.removePreview.bind(this);
this.getFileCount = this.getFileCount.bind(this);
this.getFileUploadTarget = this.getFileUploadTarget.bind(this);
this.onPreferenceChange = this.onPreferenceChange.bind(this);
this.focusTextbox = this.focusTextbox.bind(this);
this.showPostDeletedModal = this.showPostDeletedModal.bind(this);
Expand Down Expand Up @@ -497,6 +498,10 @@ export default class CreateComment extends React.Component {
return this.state.fileInfos.length + this.state.uploadsInProgress.length;
}

getFileUploadTarget() {
return this.refs.textbox;
}

focusTextbox(keepFocus = false) {
if (keepFocus || !Utils.isMobile()) {
this.refs.textbox.focus();
Expand Down Expand Up @@ -612,6 +617,7 @@ export default class CreateComment extends React.Component {
<FileUpload
ref='fileUpload'
getFileCount={this.getFileCount}
getTarget={this.getFileUploadTarget}
onFileUploadChange={this.handleFileUploadChange}
onUploadStart={this.handleUploadStart}
onFileUpload={this.handleFileUploadComplete}
Expand Down
6 changes: 6 additions & 0 deletions webapp/components/create_post.jsx
Expand Up @@ -56,6 +56,7 @@ export default class CreatePost extends React.Component {
this.onChange = this.onChange.bind(this);
this.onPreferenceChange = this.onPreferenceChange.bind(this);
this.getFileCount = this.getFileCount.bind(this);
this.getFileUploadTarget = this.getFileUploadTarget.bind(this);
this.handleKeyDown = this.handleKeyDown.bind(this);
this.handleBlur = this.handleBlur.bind(this);
this.sendMessage = this.sendMessage.bind(this);
Expand Down Expand Up @@ -456,6 +457,10 @@ export default class CreatePost extends React.Component {
return draft.fileInfos.length + draft.uploadsInProgress.length;
}

getFileUploadTarget() {
return this.refs.textbox;
}

handleKeyDown(e) {
if (this.state.ctrlSend && e.keyCode === KeyCodes.ENTER && e.ctrlKey === true) {
this.postMsgKeyPress(e);
Expand Down Expand Up @@ -652,6 +657,7 @@ export default class CreatePost extends React.Component {
<FileUpload
ref='fileUpload'
getFileCount={this.getFileCount}
getTarget={this.getFileUploadTarget}
onFileUploadChange={this.handleFileUploadChange}
onUploadStart={this.handleUploadStart}
onFileUpload={this.handleFileUploadComplete}
Expand Down
9 changes: 5 additions & 4 deletions webapp/components/file_upload.jsx
Expand Up @@ -211,20 +211,20 @@ class FileUpload extends React.Component {
// jquery-dragster doesn't provide a function to unregister itself so do it manually
target.off('dragenter dragleave dragover drop dragster:enter dragster:leave dragster:over dragster:drop');
}

emojiClick() {
this.props.onEmojiClick();
}

pasteUpload(e) {
var inputDiv = ReactDOM.findDOMNode(this.refs.input);
const {formatMessage} = this.props.intl;

if (!e.clipboardData || !e.clipboardData.items) {
return;
}

var textarea = $(inputDiv.parentNode.parentNode).find('.custom-textarea')[0];

if (textarea !== e.target && !$.contains(textarea, e.target)) {
const textarea = ReactDOM.findDOMNode(this.props.getTarget());
if (!textarea || !textarea.contains(e.target)) {
return;
}

Expand Down Expand Up @@ -386,6 +386,7 @@ FileUpload.propTypes = {
intl: intlShape.isRequired,
onUploadError: React.PropTypes.func,
getFileCount: React.PropTypes.func,
getTarget: React.PropTypes.func.isRequired,
onClick: React.PropTypes.func,
onFileUpload: React.PropTypes.func,
onUploadStart: React.PropTypes.func,
Expand Down

0 comments on commit aa92ac8

Please sign in to comment.