summaryrefslogtreecommitdiffstats
path: root/webapp/stores
diff options
context:
space:
mode:
authorHarrison Healey <harrisonmhealey@gmail.com>2017-05-04 14:54:50 -0400
committerChristopher Speller <crspeller@gmail.com>2017-05-04 14:54:50 -0400
commit44a8f76d993cdd97785cab7fd55ad9f07c3c757a (patch)
tree810bb59d319388aae57715466b244edf84644c6a /webapp/stores
parent72351c8ef8557c83b130568724fc2d6ff3acd454 (diff)
downloadchat-44a8f76d993cdd97785cab7fd55ad9f07c3c757a.tar.gz
chat-44a8f76d993cdd97785cab7fd55ad9f07c3c757a.tar.bz2
chat-44a8f76d993cdd97785cab7fd55ad9f07c3c757a.zip
PLT-6431 Prevented autocompleting while suggestions are being received (#6328)
Diffstat (limited to 'webapp/stores')
-rw-r--r--webapp/stores/suggestion_store.jsx46
1 files changed, 38 insertions, 8 deletions
diff --git a/webapp/stores/suggestion_store.jsx b/webapp/stores/suggestion_store.jsx
index a41268ccb..d1f5a64f6 100644
--- a/webapp/stores/suggestion_store.jsx
+++ b/webapp/stores/suggestion_store.jsx
@@ -222,6 +222,31 @@ class SuggestionStore extends EventEmitter {
return pretext.endsWith(matchedPretext);
}
+ setSuggestionsPending(id, pending) {
+ this.suggestions.get(id).suggestionsPending = pending;
+ }
+
+ areSuggestionsPending(id) {
+ return this.suggestions.get(id).suggestionsPending;
+ }
+
+ setCompletePending(id, pending) {
+ this.suggestions.get(id).completePending = pending;
+ }
+
+ isCompletePending(id) {
+ return this.suggestions.get(id).completePending;
+ }
+
+ completeWord(id, term = '', matchedPretext = '') {
+ this.emitCompleteWord(id, term || this.getSelection(id), matchedPretext || this.getSelectedMatchedPretext(id));
+
+ this.setPretext(id, '');
+ this.clearSuggestions(id);
+ this.clearSelection(id);
+ this.emitSuggestionsChanged(id);
+ }
+
handleEventPayload(payload) {
const {type, id, ...other} = payload.action;
@@ -248,9 +273,15 @@ class SuggestionStore extends EventEmitter {
this.clearSuggestions(id);
this.addSuggestions(id, other.terms, other.items, other.component, other.matchedPretext);
-
this.ensureSelectionExists(id);
- this.emitSuggestionsChanged(id);
+
+ this.setSuggestionsPending(id, false);
+
+ if (this.isCompletePending(id)) {
+ this.completeWord(id);
+ } else {
+ this.emitSuggestionsChanged(id);
+ }
break;
case ActionTypes.SUGGESTION_CLEAR_SUGGESTIONS:
this.setPretext(id, '');
@@ -267,12 +298,11 @@ class SuggestionStore extends EventEmitter {
this.emitSuggestionsChanged(id);
break;
case ActionTypes.SUGGESTION_COMPLETE_WORD:
- this.emitCompleteWord(id, other.term || this.getSelection(id), other.matchedPretext || this.getSelectedMatchedPretext(id));
-
- this.setPretext(id, '');
- this.clearSuggestions(id);
- this.clearSelection(id);
- this.emitSuggestionsChanged(id);
+ if (this.areSuggestionsPending(id)) {
+ this.setCompletePending(id, true);
+ } else {
+ this.completeWord(id, other.term, other.matchedPretext);
+ }
break;
}
}