Support for pasting images from clipboard

skylight
Kibigo 2017-02-28 18:52:46 -08:00
parent 5960bac11e
commit e84c1dc95f
1 changed files with 12 additions and 1 deletions

View File

@ -1,6 +1,8 @@
import AutosuggestAccountContainer from '../features/compose/containers/autosuggest_account_container'; import AutosuggestAccountContainer from '../features/compose/containers/autosuggest_account_container';
import ImmutablePropTypes from 'react-immutable-proptypes'; import ImmutablePropTypes from 'react-immutable-proptypes';
import { isRtl } from '../rtl'; import { isRtl } from '../rtl';
import { connect } from 'react-redux';
import { uploadCompose } from '../actions/compose';
const textAtCursorMatchesToken = (str, caretPosition) => { const textAtCursorMatchesToken = (str, caretPosition) => {
let word; let word;
@ -33,6 +35,7 @@ const AutosuggestTextarea = React.createClass({
value: React.PropTypes.string, value: React.PropTypes.string,
suggestions: ImmutablePropTypes.list, suggestions: ImmutablePropTypes.list,
disabled: React.PropTypes.bool, disabled: React.PropTypes.bool,
dispatch: React.PropTypes.func.isRequired,
fileDropDate: React.PropTypes.instanceOf(Date), fileDropDate: React.PropTypes.instanceOf(Date),
placeholder: React.PropTypes.string, placeholder: React.PropTypes.string,
onSuggestionSelected: React.PropTypes.func.isRequired, onSuggestionSelected: React.PropTypes.func.isRequired,
@ -173,6 +176,13 @@ const AutosuggestTextarea = React.createClass({
}) })
}, },
onPaste (e) {
if (e.clipboardData && e.clipboardData.files.length === 1) {
this.props.dispatch(uploadCompose(e.clipboardData.files));
e.preventDefault();
}
},
render () { render () {
const { value, suggestions, fileDropDate, disabled, placeholder, onKeyUp } = this.props; const { value, suggestions, fileDropDate, disabled, placeholder, onKeyUp } = this.props;
const { isFileDragging, suggestionsHidden, selectedSuggestion } = this.state; const { isFileDragging, suggestionsHidden, selectedSuggestion } = this.state;
@ -198,6 +208,7 @@ const AutosuggestTextarea = React.createClass({
onBlur={this.onBlur} onBlur={this.onBlur}
onDragEnter={this.onDragEnter} onDragEnter={this.onDragEnter}
onDragExit={this.onDragExit} onDragExit={this.onDragExit}
onPaste={this.onPaste}
style={style} style={style}
/> />
@ -214,4 +225,4 @@ const AutosuggestTextarea = React.createClass({
}); });
export default AutosuggestTextarea; export default connect()(AutosuggestTextarea);