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 filterOldSuggestions(SuggestOracle.Request request) { - List suggestions = new ArrayList(); - 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 suggestions = new ArrayList(); 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; } }