From 44217422d042a5f355d6a29a3444cd8a9edce0bb Mon Sep 17 00:00:00 2001 From: Aviral Dasgupta Date: Wed, 21 Sep 2016 07:28:07 +0530 Subject: [PATCH 1/2] Force-hide autocomplete after sending message. Fixes vector-im/vector-web#2128 --- src/components/views/rooms/Autocomplete.js | 5 +++++ src/components/views/rooms/MessageComposerInput.js | 2 ++ 2 files changed, 7 insertions(+) diff --git a/src/components/views/rooms/Autocomplete.js b/src/components/views/rooms/Autocomplete.js index 8a32883404..468884142e 100644 --- a/src/components/views/rooms/Autocomplete.js +++ b/src/components/views/rooms/Autocomplete.js @@ -18,6 +18,7 @@ export default class Autocomplete extends React.Component { this.completionPromise = null; this.onConfirm = this.onConfirm.bind(this); + this.hide = this.hide.bind(this); this.state = { // list of completionResults, each containing completions @@ -137,6 +138,10 @@ export default class Autocomplete extends React.Component { e.preventDefault(); // selectionOffset = 0, so we don't end up completing when autocomplete is hidden + this.hide(); + } + + hide() { this.setState({hide: true, selectionOffset: 0}); } diff --git a/src/components/views/rooms/MessageComposerInput.js b/src/components/views/rooms/MessageComposerInput.js index 2733bddc14..dac952a0c3 100644 --- a/src/components/views/rooms/MessageComposerInput.js +++ b/src/components/views/rooms/MessageComposerInput.js @@ -567,6 +567,8 @@ export default class MessageComposerInput extends React.Component { editorState: this.createEditorState(), }); + this.autocomplete.hide(); + return true; } From f171985e4c5ebcabbe1b6d8bcf5e0bbac99e448c Mon Sep 17 00:00:00 2001 From: Aviral Dasgupta Date: Wed, 21 Sep 2016 07:40:48 +0530 Subject: [PATCH 2/2] Fix click-to-complete in RTE Closes vector-im/vector-web#2179 --- src/components/views/rooms/Autocomplete.js | 13 +++++-------- src/components/views/rooms/MessageComposer.js | 2 +- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/components/views/rooms/Autocomplete.js b/src/components/views/rooms/Autocomplete.js index 468884142e..9be91e068a 100644 --- a/src/components/views/rooms/Autocomplete.js +++ b/src/components/views/rooms/Autocomplete.js @@ -17,8 +17,8 @@ export default class Autocomplete extends React.Component { super(props); this.completionPromise = null; - this.onConfirm = this.onConfirm.bind(this); this.hide = this.hide.bind(this); + this.onCompletionClicked = this.onCompletionClicked.bind(this); this.state = { // list of completionResults, each containing completions @@ -157,16 +157,13 @@ export default class Autocomplete extends React.Component { return done.promise; } - /** called from MessageComposerInput - * @returns {boolean} whether confirmation was handled - */ - onConfirm(): boolean { + onCompletionClicked(): boolean { if (this.countCompletions() === 0 || this.state.selectionOffset === COMPOSER_SELECTED) { return false; } - let selectedCompletion = this.state.completionList[this.state.selectionOffset - 1]; - this.props.onConfirm(selectedCompletion.range, selectedCompletion.completion); + this.props.onConfirm(this.state.completionList[this.state.selectionOffset - 1]); + this.hide(); return true; } @@ -204,7 +201,7 @@ export default class Autocomplete extends React.Component { let onMouseOver = () => this.setSelection(componentPosition); let onClick = () => { this.setSelection(componentPosition); - this.onConfirm(); + this.onCompletionClicked(); }; return React.cloneElement(completion.component, { diff --git a/src/components/views/rooms/MessageComposer.js b/src/components/views/rooms/MessageComposer.js index 395141aa15..4aeebe1411 100644 --- a/src/components/views/rooms/MessageComposer.js +++ b/src/components/views/rooms/MessageComposer.js @@ -178,7 +178,7 @@ export default class MessageComposer extends React.Component { _tryComplete(): boolean { if (this.refs.autocomplete) { - return this.refs.autocomplete.onConfirm(); + return this.refs.autocomplete.onCompletionClicked(); } return false; }