fix tab focus issue in MessageComposerInput

onTab was incorrectly implemented causing forceComplete instead of
focusing the editor
This commit is contained in:
Aviral Dasgupta 2017-02-10 02:06:06 +05:30
parent aaac06c6d3
commit 46d30c378d
No known key found for this signature in database
GPG key ID: 5FD1E9F4FFD3DA80
2 changed files with 19 additions and 8 deletions

View file

@ -149,6 +149,7 @@ export default class Autocomplete extends React.Component {
const done = Q.defer();
this.setState({
forceComplete: true,
hide: false,
}, () => {
this.complete(this.props.query, this.props.selection).then(() => {
done.resolve();
@ -185,6 +186,11 @@ export default class Autocomplete extends React.Component {
}
}
setState(state, func) {
super.setState(state, func);
console.log(state);
}
render() {
const EmojiText = sdk.getComponent('views.elements.EmojiText');

View file

@ -400,7 +400,8 @@ export default class MessageComposerInput extends React.Component {
*/
setState(state, callback) {
if (state.editorState != null) {
state.editorState = RichText.attachImmutableEntitiesToEmoji(state.editorState);
state.editorState = RichText.attachImmutableEntitiesToEmoji(
state.editorState);
if (state.editorState.getCurrentContent().hasText()) {
this.onTypingActivity();
@ -413,15 +414,17 @@ export default class MessageComposerInput extends React.Component {
}
}
super.setState(state, (state, props, context) => {
super.setState(state, () => {
if (callback != null) {
callback(state, props, context);
callback();
}
if (this.props.onContentChanged) {
const textContent = state.editorState.getCurrentContent().getPlainText();
const selection = RichText.selectionStateToTextOffsets(state.editorState.getSelection(),
state.editorState.getCurrentContent().getBlocksAsArray());
const textContent = this.state.editorState
.getCurrentContent().getPlainText();
const selection = RichText.selectionStateToTextOffsets(
this.state.editorState.getSelection(),
this.state.editorState.getCurrentContent().getBlocksAsArray());
this.props.onContentChanged(textContent, selection);
}
@ -616,11 +619,13 @@ export default class MessageComposerInput extends React.Component {
// tab and shift-tab are mapped to down and up arrow respectively
onTab = async (e) => {
console.log('onTab');
e.preventDefault(); // we *never* want tab's default to happen, but we do want up/down sometimes
const didTab = await (e.shiftKey ? this.onUpArrow : this.onDownArrow)(e);
if (!didTab && this.autocomplete) {
if (this.autocomplete.state.completionList.length === 0) {
await this.autocomplete.forceComplete();
this.onDownArrow(e);
} else {
await (e.shiftKey ? this.onUpArrow : this.onDownArrow)(e);
}
};