summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbjorn <bjorn@bringert.net>2008-10-28 12:59:00 +0000
committerbjorn <bjorn@bringert.net>2008-10-28 12:59:00 +0000
commit8e43cfb8a8ce4a6c4c608678633c0c5ec67adfff (patch)
tree703600ffa8c8ecdf682da9efd424ddce6fcfcdc8
parent1a34a24df0c38220e2444d9253a69df30259dc36 (diff)
GWT: better heuristics for when to ask the server for completions.
-rw-r--r--src/server/gwt/src/se/chalmers/cs/gf/gwt/client/CompletionOracle.java22
1 files changed, 16 insertions, 6 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 9a9b5080d..dcd1d2928 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
@@ -8,7 +8,7 @@ import com.google.gwt.user.client.ui.SuggestOracle;
public class CompletionOracle extends SuggestOracle {
- private static final int LIMIT_SCALE_FACTOR = 10;
+ private static final int LIMIT_SCALE_FACTOR = 4;
private PGF pgf;
@@ -81,14 +81,24 @@ public class CompletionOracle extends SuggestOracle {
/** Filters old suggestions and checks if we still have enough suggestions. */
private List<CompletionSuggestion> filterOldSuggestions(SuggestOracle.Request request) {
- List<CompletionSuggestion> suggestions = new ArrayList<CompletionSuggestion>();
- if (oldQuery != null && request.getQuery().startsWith(oldQuery)) {
+ 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 (oldSuggestions.isEmpty()) {
+ return Collections.emptyList();
+ }
+ // If the input 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) == ' ') {
+ return null;
+ }
+ List<CompletionSuggestion> suggestions = new ArrayList<CompletionSuggestion>();
for (CompletionSuggestion c : oldSuggestions) {
- if (c.getReplacementString().startsWith(request.getQuery())) {
+ if (c.getReplacementString().startsWith(query)) {
suggestions.add(c);
}
- }
- if (suggestions.size() > 1 && (suggestions.size() >= request.getLimit() || oldSuggestions.size() < request.getLimit())) {
+ }
+ if (suggestions.size() >= request.getLimit() || oldSuggestions.size() < request.getLimit()) {
return suggestions;
}
}