Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
make clicking autocomplete suggestions work again
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
  • Loading branch information
t3chguy committed Jul 24, 2018
1 parent ef39327 commit afa19cd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
3 changes: 2 additions & 1 deletion res/css/views/rooms/_Autocomplete.scss
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@
flex-flow: wrap;
}

.mx_Autocomplete_Completion.selected {
.mx_Autocomplete_Completion.selected,
.mx_Autocomplete_Completion:hover {
background: $menu-bg-color;
outline: none;
}
Expand Down
9 changes: 4 additions & 5 deletions src/components/views/rooms/Autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,12 @@ export default class Autocomplete extends React.Component {
return done.promise;
}

onCompletionClicked(): boolean {
if (this.countCompletions() === 0 || this.state.selectionOffset === COMPOSER_SELECTED) {
onCompletionClicked(selectionOffset: number): boolean {
if (this.countCompletions() === 0 || selectionOffset === COMPOSER_SELECTED) {
return false;
}

this.props.onConfirm(this.state.completionList[this.state.selectionOffset - 1]);
this.props.onConfirm(this.state.completionList[selectionOffset - 1]);
this.hide();

return true;
Expand Down Expand Up @@ -264,8 +264,7 @@ export default class Autocomplete extends React.Component {
position++;

const onClick = () => {
this.setSelection(componentPosition);
this.onCompletionClicked();
this.onCompletionClicked(componentPosition);
};

return React.cloneElement(completion.component, {
Expand Down
10 changes: 9 additions & 1 deletion src/components/views/rooms/MessageComposerInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -1301,6 +1301,14 @@ export default class MessageComposerInput extends React.Component {
await this.setDisplayedCompletion(null); // restore originalEditorState
};

onAutocompleteConfirm = (displayedCompletion: ?Completion) => {
this.focusComposer();
// XXX: this fails if the composer isn't focused so focus it and delay the completion until next tick
setImmediate(() => {
this.setDisplayedCompletion(displayedCompletion);
});
};

/* If passed null, restores the original editor content from state.originalEditorState.
* If passed a non-null displayedCompletion, modifies state.originalEditorState to compute new state.editorState.
*/
Expand Down Expand Up @@ -1563,7 +1571,7 @@ export default class MessageComposerInput extends React.Component {
<Autocomplete
ref={(e) => this.autocomplete = e}
room={this.props.room}
onConfirm={this.setDisplayedCompletion}
onConfirm={this.onAutocompleteConfirm}
onSelectionChange={this.setDisplayedCompletion}
query={ this.suppressAutoComplete ? '' : this.getAutocompleteQuery(activeEditorState) }
selection={this.getSelectionRange(activeEditorState)}
Expand Down

0 comments on commit afa19cd

Please sign in to comment.