Fix ctrl+enter not submitting toot when text cursor is composing image description (#8273)

This commit is contained in:
Spanky 2018-08-18 12:40:35 -05:00 committed by Eugen Rochko
parent 298ee84488
commit 7a0f781aa9
2 changed files with 18 additions and 0 deletions

View file

@ -20,6 +20,7 @@ export default class Upload extends ImmutablePureComponent {
onUndo: PropTypes.func.isRequired, onUndo: PropTypes.func.isRequired,
onDescriptionChange: PropTypes.func.isRequired, onDescriptionChange: PropTypes.func.isRequired,
onOpenFocalPoint: PropTypes.func.isRequired, onOpenFocalPoint: PropTypes.func.isRequired,
onSubmit: PropTypes.func.isRequired,
}; };
state = { state = {
@ -28,6 +29,17 @@ export default class Upload extends ImmutablePureComponent {
dirtyDescription: null, dirtyDescription: null,
}; };
handleKeyDown = (e) => {
if (e.keyCode === 13 && (e.ctrlKey || e.metaKey)) {
this.handleSubmit();
}
}
handleSubmit = () => {
this.handleInputBlur();
this.props.onSubmit();
}
handleUndoClick = () => { handleUndoClick = () => {
this.props.onUndo(this.props.media.get('id')); this.props.onUndo(this.props.media.get('id'));
} }
@ -93,6 +105,7 @@ export default class Upload extends ImmutablePureComponent {
onFocus={this.handleInputFocus} onFocus={this.handleInputFocus}
onChange={this.handleInputChange} onChange={this.handleInputChange}
onBlur={this.handleInputBlur} onBlur={this.handleInputBlur}
onKeyDown={this.handleKeyDown}
/> />
</label> </label>
</div> </div>

View file

@ -2,6 +2,7 @@ import { connect } from 'react-redux';
import Upload from '../components/upload'; import Upload from '../components/upload';
import { undoUploadCompose, changeUploadCompose } from '../../../actions/compose'; import { undoUploadCompose, changeUploadCompose } from '../../../actions/compose';
import { openModal } from '../../../actions/modal'; import { openModal } from '../../../actions/modal';
import { submitCompose } from '../../../actions/compose';
const mapStateToProps = (state, { id }) => ({ const mapStateToProps = (state, { id }) => ({
media: state.getIn(['compose', 'media_attachments']).find(item => item.get('id') === id), media: state.getIn(['compose', 'media_attachments']).find(item => item.get('id') === id),
@ -21,6 +22,10 @@ const mapDispatchToProps = dispatch => ({
dispatch(openModal('FOCAL_POINT', { id })); dispatch(openModal('FOCAL_POINT', { id }));
}, },
onSubmit () {
dispatch(submitCompose());
},
}); });
export default connect(mapStateToProps, mapDispatchToProps)(Upload); export default connect(mapStateToProps, mapDispatchToProps)(Upload);