summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbjorn <bjorn@bringert.net>2008-11-03 21:07:53 +0000
committerbjorn <bjorn@bringert.net>2008-11-03 21:07:53 +0000
commit3a6466ac1a686f262b62e4f4b455f57b284e0911 (patch)
tree107159ae3428862c0ab4afe4d472661f7c5e1bc9 /src
parentd6f09a941f4b5f96d4c7364461c318ca64389b17 (diff)
Fix GWT client-side completion caching bug. Typing a space and then a letter quickly would cause the first request to be cancelled, and the second would use the two steps old results, which didn't go past the space => 0 completions.
Diffstat (limited to 'src')
-rw-r--r--src/server/gwt/src/se/chalmers/cs/gf/gwt/client/CompletionOracle.java22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/server/gwt/src/se/chalmers/cs/gf/gwt/client/CompletionOracle.java b/src/server/gwt/src/se/chalmers/cs/gf/gwt/client/CompletionOracle.java
index edf8cc1ca..5953aa24f 100644
--- a/src/server/gwt/src/se/chalmers/cs/gf/gwt/client/CompletionOracle.java
+++ b/src/server/gwt/src/se/chalmers/cs/gf/gwt/client/CompletionOracle.java
@@ -40,12 +40,21 @@ public class CompletionOracle extends SuggestOracle {
public void setGrammarName(String pgfName) {
this.pgfName = pgfName;
+ clearState();
}
public void setInputLangs(List<String> inputLangs) {
this.inputLangs = inputLangs;
+ clearState();
+ }
+
+ private void clearState () {
this.oldQuery = null;
this.oldSuggestions = Collections.emptyList();
+ if (jsonRequest != null) {
+ jsonRequest.cancel();
+ jsonRequest = null;
+ }
}
public List<String> getInputLangs() {
@@ -76,10 +85,11 @@ public class CompletionOracle extends SuggestOracle {
}
public void requestSuggestions(SuggestOracle.Request request, SuggestOracle.Callback callback) {
-
// Only allow a single completion request at a time
- if (jsonRequest != null)
+ if (jsonRequest != null) {
jsonRequest.cancel();
+ jsonRequest = null;
+ }
List<CompletionSuggestion> suggestions = filterOldSuggestions(request);
if (suggestions != null) {
@@ -93,13 +103,14 @@ public class CompletionOracle extends SuggestOracle {
private List<CompletionSuggestion> filterOldSuggestions(SuggestOracle.Request request) {
String query = request.getQuery();
if (query.length() > 0 && oldQuery != null && query.startsWith(oldQuery)) {
- // If the prefix had no completions, so there is no way that the current input will.
+ // If the prefix had no completions, there is no way that the current input will.
if (oldSuggestions.isEmpty()) {
return Collections.emptyList();
}
- // If the input ends in whitespace, always get completions from the server,
+ // If the new input since the previous query ends in whitespace,
+ // always get completions from the server,
// since the old suggestions won't include the next word.
- if (query.charAt(query.length() - 1) == ' ') {
+ if (query.indexOf(' ', oldQuery.length()) != -1) {
return null;
}
List<CompletionSuggestion> suggestions = new ArrayList<CompletionSuggestion>();
@@ -122,6 +133,7 @@ public class CompletionOracle extends SuggestOracle {
jsonRequest = pgf.complete(getGrammarName(), request.getQuery(), getInputLangs(), null, LIMIT_SCALE_FACTOR * request.getLimit(),
new PGF.CompleteCallback() {
public void onResult(PGF.Completions completions) {
+ jsonRequest = null;
List<CompletionSuggestion> suggestions = new ArrayList<CompletionSuggestion>();
for (PGF.Completion completion : completions.iterable()) {
suggestions.add(new CompletionSuggestion(completion.getText()));